Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookie URLs aren't build correctly #756

Closed
fabsh opened this issue Apr 19, 2016 · 4 comments
Closed

Cookie URLs aren't build correctly #756

fabsh opened this issue Apr 19, 2016 · 4 comments
Labels

Comments

@fabsh
Copy link

fabsh commented Apr 19, 2016

As soon as I turn on login via username/password I can't get to the main selfoss page anymore. Turning on DEBUG gives the message that I am logged in but then I it reports the session isn't valid. Looking at the generated cookie, I figured out that the cookie domain is subdomain.domain.com and the path is subdomain.domain.com -- this is obviously wrong. I patched this by hardcoding my domain to subdomain.domain.com and the path to / in Authentication.php like this:

// check for SSL proxy and special cookie options
        if(isset($_SERVER['HTTP_X_FORWARDED_SERVER']) && isset($_SERVER['HTTP_X_FORWARDED_HOST'])
           && ($_SERVER['HTTP_X_FORWARDED_SERVER']===$_SERVER['HTTP_X_FORWARDED_HOST'])) {
            $cookie_path = '/';
            $cookie_domain = 'subdomain.domain.com';
        } else {
            // cookie path is script dir.
            $cookie_path = '/';
            $cookie_domain = 'subdomain.domain.com';
        }

Now authentication works but this is obviously very ugly. I'm running on a Webfaction vserver. I'm guessing the $_SERVER variables are messed up somehow but know to little to know how exactly that is broken and why.

@nopoz
Copy link

nopoz commented May 23, 2016

The above fix worked for me. Having the same problem. I was not getting redirected when logging in with the authentication page. Using nginx frontend to redirect to apache backend.

@lost-geographer
Copy link
Contributor

lost-geographer commented Jun 4, 2016

I had the same invalid session issue as @fabsh and @doucheymcdoucherson. The problem seems to be that, when it runs behind a proxy, Selfoss builds an invalid cookie's URL: the domain is duplicated. You can see something like this in the DEBUG log:

set cookie on domain.com/domain.com/path/ expiring in 2592000 seconds

Or this (if Selfoss is installed in a subdomain):

set cookie on sub.domain.com/sub.domain.com/path/ expiring in 2592000 seconds

As the cookie's URL is build from the $cookie_domain and the $cookie_path in Authentication.php (lines 37-38), I isolated the two variables' code and its results in order to identify the problem:

Code:

$cookie_path = '/'.$_SERVER['SERVER_NAME'].preg_replace('/\/[^\/]+$/','',$_SERVER['PHP_SELF']).'/';
$cookie_domain = $_SERVER['HTTP_X_FORWARDED_SERVER'];

Results:

$cookie_path = /domain.com/path/
$cookie_domain = domain.com

Solution:

As you can see, part of the $cookie_path result is redundant with $cookie_domain. Actually, in the $cookie_path code there is the $_SERVER['SERVER_NAME'] variable that makes the same result as $cookie_domain, so I just removed it. And this is the new code (line 37):

$cookie_path = preg_replace('/\/[^\/]+$/','',$_SERVER['PHP_SELF']).'/';

I don't fully understand how the $cookie_path variable is used, but this little workaround seems to solve the problem.

@jtojnar
Copy link
Member

jtojnar commented Jun 6, 2016

Does #766 fix your problem?

@lost-geographer
Copy link
Contributor

@jtojnar No. I suppose that #766 didn't work because it changes URL building rules only in case of a normal http connection. This problem occurs in case of an https or proxy connection.

However, i think your idea is good: it may allow Selfoss to get rid of the protocol verification in Autentication.php and View.php...

@jtojnar jtojnar added the bug label Feb 5, 2017
niol added a commit to niol/selfoss that referenced this issue Mar 3, 2017
This should fix fossar#756 and give a workaround for other cookie related issues.
niol added a commit to niol/selfoss that referenced this issue Mar 3, 2017
This should fix fossar#756 and give a workaround for other cookie related issues.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants