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

'Remember me' not working because cookie expire is in wrong format #15625

Closed
matzesa opened this issue Feb 26, 2020 · 15 comments · Fixed by #15633
Closed

'Remember me' not working because cookie expire is in wrong format #15625

matzesa opened this issue Feb 26, 2020 · 15 comments · Fixed by #15633
Assignees
Labels
Bug For errors / faults / flaws / inconsistencies etc. Regression Indicates a feature used to work in a certain way but it no longer does even though it should.
Milestone

Comments

@matzesa
Copy link

matzesa commented Feb 26, 2020

After logging in the MATOMO_SESSID Cookie is changed via the http header set-cookie and an expires directive is added. But the format of the value is unixtime instead of date (https://tools.ietf.org/html/rfc6265#section-4.1)

Example (Version 3.13.3):

Set-Cookie: MATOMO_SESSID=380lf4cjmaenc605u73dgklnq9; expires=1583920346; path=/; secure; httponly; SameSite=Lax

Found the following code line, perhaps it helps, but did not inspect deeper:

$headerStr .= '; expires=' . $expires;

Here it seems to be converted:

. (empty($Expires) ? '' : '; expires=' . gmdate('D, d-M-Y H:i:s', $Expires) . ' GMT')

@tsteur tsteur added the Bug For errors / faults / flaws / inconsistencies etc. label Feb 26, 2020
@tsteur tsteur added this to the 3.13.4 milestone Feb 26, 2020
@tsteur
Copy link
Member

tsteur commented Feb 26, 2020

Thanks @matzesa very appreciated.

@dev-101
Copy link

dev-101 commented Feb 26, 2020

Is this the cause of Matomo session lasting for few hours only? Ever since upgrading to the latest version 3.13.3 on one site, I always get login screen, even with remember me option checked. What have you done wrong this time? :)

@Findus23
Copy link
Member

@Findus23 Findus23 added the Regression Indicates a feature used to work in a certain way but it no longer does even though it should. label Feb 27, 2020
@adegans
Copy link

adegans commented Feb 27, 2020

For me to 'remember me' doesn't work either.
But, it's not so much the checkbox as the session that's broken I think.

I tried logging out and then back in to sort of set a new login hash/id/thing - In case an old session or whatever was lingering around.
But as soon as I close the tab and load Matomo again I have to log in again.
So probably a session/cookie issue.
Worked fine in 3.13.2 (or whatever the version before was)

@benkuper
Copy link

Same here, is there a workaround that we can do in the meantime ?

@sgiehl sgiehl self-assigned this Feb 28, 2020
sgiehl added a commit that referenced this issue Feb 28, 2020
@sgiehl sgiehl linked a pull request Feb 28, 2020 that will close this issue
@Findus23
Copy link
Member

@benkuper
You can in the meantime try to apply this change from #15633 and report back if it works for you:

diff --git a/core/Session.php b/core/Session.php
index f2f984d357e..dd5b1229d70 100644
--- a/core/Session.php
+++ b/core/Session.php
@@ -222,7 +222,7 @@ public static function writeCookie($name, $value, $expires = 0, $path = '/', $do
     {
         $headerStr = 'Set-Cookie: ' . rawurlencode($name) . '=' . rawurlencode($value);
         if ($expires) {
-            $headerStr .= '; expires=' . $expires;
+            $headerStr .= '; expires=' . gmdate('D, d-M-Y H:i:s', $expires) . ' GMT';
         }
         if ($path) {
             $headerStr .= '; path=' . $path;

@benkuper
Copy link

Thanks @Findus23 , it seems to do the job !
I have just tested by closing the browser and going back, but at least this works. This should definitely be integrated in next version :)

diosmosis pushed a commit that referenced this issue Mar 2, 2020
* Fix session expire

fixes #15625

* adds some tests
@sgiehl sgiehl closed this as completed Mar 2, 2020
@mattab mattab changed the title MATOMO_SESSID expires directive with wrong format cookie MATOMO_SESSID expires directive has wrong format Mar 24, 2020
@mattab mattab added Regression Indicates a feature used to work in a certain way but it no longer does even though it should. and removed Regression Indicates a feature used to work in a certain way but it no longer does even though it should. labels Mar 24, 2020
@mattab mattab changed the title cookie MATOMO_SESSID expires directive has wrong format 'Remember me' not working because cookie expire is in wrong format Mar 24, 2020
jonasgrilleres pushed a commit to 1024pix/pix-analytics that referenced this issue Sep 22, 2020
* Fix session expire

fixes matomo-org#15625

* adds some tests
jbuget pushed a commit to 1024pix/pix-analytics that referenced this issue Sep 26, 2020
* Fix session expire

fixes matomo-org#15625

* adds some tests
@cbeams
Copy link

cbeams commented Feb 1, 2021

I am running Matomo v4.1.1 and still seeing the old, erroneous epoch time expiration values in the cookie. If I understand this issue and the linked PR correctly, this problem got fixed and integrated back in the 3.x line. How could it be that I'm still seeing this behavior? Anyone else still having the problem?

@dev-101
Copy link

dev-101 commented Feb 1, 2021

Have you tried to sign-out and sign-in? This step was required to complete the fix iirc. But, I guess you already tried that. So far, no issues here since the original fix.

@cbeams
Copy link

cbeams commented Feb 1, 2021

Sorry, I just realized that I am in fact seeing the proper date string, not the old unix time string, and I even see that the date is updated on every refresh within the same session. Currently the expiry time reads "2021-07-31T10:10:33.600Z", but regardless, I still get logged out. Not sure what the problem could be. I've tried logging out, etc. It's as if the cookie just isn't being read / respected.

@dev-101
Copy link

dev-101 commented Feb 1, 2021

Maybe session file on your server gets removed for some reason. Don't know what could be the problem.

@cbeams
Copy link

cbeams commented Feb 1, 2021

False alarm. I've played with this further, and now everything is working as expected. I don't know exactly what made the difference, but perhaps I hadn't fully / properly tested by logging out, quitting the browser and restarting before. All good now.

@nebulade
Copy link

nebulade commented Feb 3, 2021

To get some better picture, I am facing the same issue and upon some investigation, I've seen that it our instance never stores session files on the disk, but rather appears to have a session table in the database. What is the connection between that table and the login session or are these some other kind of sessions?

@sgiehl
Copy link
Member

sgiehl commented Feb 3, 2021

@nebulade Matomo switched to using database sessions instead of files a while ago. So the table should hold all login sessions.

@nebulade
Copy link

nebulade commented Feb 3, 2021

Thanks for the clarification @sgiehl !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc. Regression Indicates a feature used to work in a certain way but it no longer does even though it should.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants