(5.0) Video broken under reverse proxy due to wrong domain.

General discussions.

Moderator: moderators

(5.0) Video broken under reverse proxy due to wrong domain.

Postby chris.henderson » Sat Sep 27, 2014 12:41 am

This issue did not exist for me in this form in 4.9.

Under a reverse proxy the client will attempt to access the proxied domain rather than the proxy itself when retrieving crossdomain.xml and the video stream itself. This results in a "Video not found or access denied" error.

Example Chrome console output:
(http://i168.photobucket.com/albums/u171 ... bsonic.png)
Image

You can see that the client is attempting to use the name of my upstream block as the domain to reference (without using the upstream block the above simply changes from http://subsonic/subsonic/foo%20bar to http://localhost:4040/subsonic/foo%20bar).

Subsonic is reverse proxied by Nginx with the following relevant configuration
Code: Select all
upstream subsonic {
        server localhost:4040;
}

Code: Select all
location /subsonic {
        proxy_pass              http://subsonic;
        proxy_set_header        X-Real-IP  $remote_addr;
        proxy_set_header        X-Forwarded-Host $host;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
}


Subsonic's default config:
Code: Select all
SUBSONIC_HOST=127.0.0.1
SUBSONIC_PORT=4040
SUBSONIC_CONTEXT_PATH=/subsonic
SUBSONIC_ARGS="--max-memory=5120 --host=${SUBSONIC_HOST} --port=${SUBSONIC_PORT} --context-path=${SUBSONIC_CONTEXT_PATH}"


I've managed a workaround by adding...
Code: Select all
129.219.26.2 subsonic

...to each client's hosts file so that it can actually resolve the name, but this is unsatisfactory as even a medium term response.

Does anyone know of an Nginx directive for making the player more aware of its position in the proxy? Or point me to where in the code I can set this straight?

Thank you, very much.
chris.henderson
 
Posts: 4
Joined: Fri Sep 26, 2014 11:57 pm

Re: (5.0) Video broken under reverse proxy due to wrong doma

Postby Rezero » Sat Sep 27, 2014 2:27 am

Wanted to log in to confirm this. I use Apache's ProxyPass feature to route requests to mydomain/subsonic to 127.0.0.1:4040/subsonic. This works fine for music, but any attempts to play video result in the player looking at http://127.0.0.1/subsonic instead of http://mydomain/subsonic.
Rezero
 
Posts: 4
Joined: Sat Jul 20, 2013 4:18 pm

Re: (5.0) Video broken under reverse proxy due to wrong doma

Postby daily-freak » Mon Sep 29, 2014 11:56 am

I can also confirm this problem. This is happening for me using apache2 (up to date), gentoo linux und standalone-subsonic with reverse-proxy. A fix would be nice. For example when serving the Video-Url extract the domain out of the request-header.

Greetings

Edit: I did a small research on this..

This is the source of the video-controller in 4.9
http://sourceforge.net/p/subsonic/code/ ... oller.java

And this in 5.0
http://sourceforge.net/p/subsonic/code/ ... oller.java

As you can see the handling of the video urls has changed I think according to the new player. in 4.9 the original request and response have been forwarded, now they are interpreted in the controller. There is the error. Currently I have no solution. Maybe if I have time I will check if I find a solution. But a solution by sindre would be nicer because her really knows what he is doing there and why he is doing it
daily-freak
 
Posts: 10
Joined: Mon May 12, 2014 10:03 am

Re: (5.0) Video broken under reverse proxy due to wrong doma

Postby chris.henderson » Mon Sep 29, 2014 2:32 pm

daily-freak wrote:...
And this in 5.0
http://sourceforge.net/p/subsonic/code/ ... oller.java


I have my hunches. In there we have lines 71-74:

Code: Select all
        String remoteStreamUrl = StringUtil.rewriteRemoteUrl(streamUrl, urlRedirectionEnabled, urlRedirectFrom,
                urlRedirectContextPath, localIp, localPort);
        String remoteCoverArtUrl = StringUtil.rewriteRemoteUrl(coverArtUrl, urlRedirectionEnabled, urlRedirectFrom,
                urlRedirectContextPath, localIp, localPort);


Which uses net.sourceforge.subsonic.util.StringUtil.rewriteRemoteUrl:

Code: Select all
    public static String rewriteRemoteUrl(String localUrl, boolean urlRedirectionEnabled, String urlRedirectFrom,
            String urlRedirectContextPath, String localIp, int localPort) throws MalformedURLException {

        URLBuilder urlBuilder = new URLBuilder(localUrl);
        if (urlRedirectionEnabled) {
            String subsonicHost = urlRedirectFrom + ".subsonic.org";
            urlBuilder.setProtocol(URLBuilder.HTTP);
            urlBuilder.setHost(subsonicHost);
            urlBuilder.setPort(80);
            if (StringUtils.isNotBlank(urlRedirectContextPath)) {
                urlBuilder.setFile(urlBuilder.getFile().replaceFirst("^/" + urlRedirectContextPath, ""));
            }

        } else {
            urlBuilder.setProtocol(URLBuilder.HTTP);
            urlBuilder.setHost(localIp);
            urlBuilder.setPort(localPort);
        }
        return urlBuilder.getURLAsString();
    }


It kind of looks like urlRedirectionEnabled is a semaphore for having a subsonic.org subdomain. If not a subsonic.org subdomain then just concatenate the protocol, local ip, and local port in a URLbuilder. Those two were set back in the VideoController at lines 69-70:

Code: Select all
        String localIp = settingsService.getLocalIpAddress();
        int localPort = settingsService.getPort();


Which are just getters from the net.sourceforge.subsonic.service.SettingsService (http://sourceforge.net/p/subsonic/code/ ... java#l1242).

I may have read urlRedirectionEnabled wrong, but overall it looks like the VideoPlayerController has taken on URL writing responsibilities without covering the case of a reverse proxy. I would love to work on a fix (no sarcasm!) but I just don't have the time nor wherewithal. However, hopefully this gets contributors on the right path.
chris.henderson
 
Posts: 4
Joined: Fri Sep 26, 2014 11:57 pm

Re: (5.0) Video broken under reverse proxy due to wrong doma

Postby phillipah » Wed Oct 01, 2014 8:18 pm

I am having the same problem... Anyone know when we can see a fix?
phillipah
 
Posts: 5
Joined: Sat Aug 25, 2012 4:18 am

Re: (5.0) Video broken under reverse proxy due to wrong doma

Postby shikasta » Sun Oct 12, 2014 1:40 pm

I too have this issue when using an Apache proxy. I believe the actual problem is that the new rewrite settings assume only two contingencies: passthrough on port 4040 to subsonic (by setting --host in /etc/defaults/subsonic), or use of a subdomain YOU.subsonic.org.

The parameter UrlRedirectFrom in subsonic.properties sets this subdomain, and is read elsewhere using settingsService.getUrlRedirectFrom() and appending ".subsonic.org". Unfortuantely, simply removing ".subsonic.org" from everywhere this appears and brute forcing it to my actual host domain doesn't quite work, so I suspect I have missed a step somewhere.

It would be far more to the point to replace the "easy to remember address" setting on the Settings > Network page, with something that accepts a fully qualifying domain name, and maybe with auto-complete to .subsonic.org for convenience. Then this would work correctly with the current two contingencies and any other host name.
shikasta
 
Posts: 10
Joined: Fri Nov 09, 2012 2:33 pm

Re: (5.0) Video broken under reverse proxy due to wrong doma

Postby Chronic » Mon Oct 13, 2014 6:06 pm

This is a dealbreaker for me. Rolled back to 4.9 until this gets fixed.
Chronic
 
Posts: 10
Joined: Wed Jun 29, 2011 5:35 am

Re: (5.0) Video broken under reverse proxy due to wrong doma

Postby phillipah » Fri Oct 31, 2014 4:33 am

bump... please can someone fix this...
phillipah
 
Posts: 5
Joined: Sat Aug 25, 2012 4:18 am

Re: (5.0) Video broken under reverse proxy due to wrong doma

Postby shikasta » Fri Oct 31, 2014 11:45 am

Not a fix, but workaround that works:

http://techblog.jeppson.org/2014/09/fix ... 0-upgrade/

The key is to insert

ProxyPreserveHost on

into your apache VirtualHost config, before the proxypass
shikasta
 
Posts: 10
Joined: Fri Nov 09, 2012 2:33 pm

Re: (5.0) Video broken under reverse proxy due to wrong doma

Postby phillipah » Fri Oct 31, 2014 4:55 pm

shikasta wrote:Not a fix, but workaround that works:

http://techblog.jeppson.org/2014/09/fix ... 0-upgrade/

The key is to insert

ProxyPreserveHost on

into your apache VirtualHost config, before the proxypass


That worked for me! Thanks!

Another thing i wanted to add is that in my configuration i have all http requested getting redirected to https and it still worked just fine. I thought i would have to allow the stream to be http but it was not necessary.
phillipah
 
Posts: 5
Joined: Sat Aug 25, 2012 4:18 am

Re: (5.0) Video broken under reverse proxy due to wrong doma

Postby daily-freak » Fri Nov 14, 2014 10:21 am

Didn't work for me. It should work if your Server is reachable over http, but if you are using https the URL is being resolved to "http://<yourUrl>" which leads to a 404.

Greetings
daily-freak
 
Posts: 10
Joined: Mon May 12, 2014 10:03 am

Re: (5.0) Video broken under reverse proxy due to wrong doma

Postby chris.henderson » Wed Nov 19, 2014 1:44 pm

shikasta wrote:Not a fix, but workaround that works:

http://techblog.jeppson.org/2014/09/fix ... 0-upgrade/

The key is to insert

ProxyPreserveHost on

into your apache VirtualHost config, before the proxypass


Note that the analog to this in Nginx is the following:

Code: Select all
proxy_set_header Host $host;


And yes, it appears to be working for now. Thank you.
chris.henderson
 
Posts: 4
Joined: Fri Sep 26, 2014 11:57 pm

Re: (5.0) Video broken under reverse proxy due to wrong doma

Postby Rezero » Fri Nov 28, 2014 2:01 am

daily-freak wrote:Didn't work for me. It should work if your Server is reachable over http, but if you are using https the URL is being resolved to "http://<yourUrl>" which leads to a 404.

Greetings


In this case, you should enable SSL through Subsonic and set up forwarding to Subsonic's HTTPS port. The extra overhead is unwelcome, but minimal, and it will correctly resolve to https://<mydomain>
Rezero
 
Posts: 4
Joined: Sat Jul 20, 2013 4:18 pm


Return to General

Who is online

Users browsing this forum: No registered users and 21 guests