Fix StaySignedIn mechanism#2213
Open
Lucas-C wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue symptoms
When performing a login with the
longlastingsessionformcheckbox set,the login succeeds but the session only last 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 remove seemingly useless calls to
sessionManager->destroy(),sessionManager->start()&sessionManager->regenerateId()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