Fix StaySignedIn mechanism - #2213
Conversation
|
Another closed issue related to my persistent sign-in problem: #1228 I just figured that in my case the issue was also caused by this PHP configuration value: I will try to continue working on this and provide more information if I can. Maybe in the end the best/first thing to do would be to simply document the impact of PHP |
cabebbf to
6224606
Compare
|
IMHO this PR is ready for review & merging. This PR includes:
Configuring session max durationShaarli relies on PHP native session handling based on Due to this, the session duration is limited by the value of If you want to benefit from Shaarli stay-signed-in feature that only terminates your session after one year of inactivity, you should set |
|
I have experienced another session reset and thought this bug was not solved, I got a session lasting several hours after that, so I think this PR definitively solves the problem. |
|
Hi, I don't understand what this is supposed to fix. I can't reproduce the problem on my local instance (apache + php-fpm, Debian 12) Are you able to reproduce the problem on a stock shaarli installation? With or without |
|
Hi.
What is your value for
I haven't tried.
I think problem happens with both, but I intially had session protection enabled.
Yes, somehow.
Manual and relatively old.
Which logs?
None that I'm aware of, but I can check specific settings if you want? |
/etc/php/8.2/fpm/php.ini:session.gc_maxlifetime = 1440
I think there is your problem. When If your client IP address changes regularly, the only way to stay signed in is Please try running v0.16.2 with no changes to the code, disabling session protection, login with "Stay signed in" enabled, and use shaarli for a while, then confirm or not if it solves your problem. |
Issue symptoms
When performing a login with the
longlastingsessionformcheckbox set,the login succeeds but the session lasts less than 1 hour.
Issue analysis
After a successful login, shaarli performs a redirect in
LoginController->login().During this redirect operation, the following state is lost:
SessionManager->staySignedInis switched fromtruetofalseSessionManager->session['expires_on']is reset to a short (1 hour) session, due to the callSessionManager->extendSession()made fromLoginManager->checkLoginState()inindex.phpThe consequence is that the
SessionManager->session['expires_on']is never persisted to 1 year value, only to a 1 hour value.Fix description
First, there is an issue with
SessionManager->$staySignedInthat is always initialized tofalse.The fix there was to figure if we are in a long-lasting session based on
$this->session['expires_on'],and in this case set it to
trueinSessionManager->initialize().The other part of the fix was to ensure that
SessionManager->session['expires_on']is correctly persisted between the call toLoginController->login(), the redirect and the page reload.My solution was to simply perform the calls to
sessionManager->destroy(),sessionManager->start()&sessionManager->regenerateId()a bit earlier inLoginController->renewUserSession().There may be other solutions to solve this problem, but this seemed the cleanest to me.
Suggestions for alternative fixes are welcome.
Note that there is also this related existing issue to redesign the login management code: #1150