Repository navigation
Conversation
…ches Treating every login on a brand with user switching as an add-user login changed what signing in as someone else means and skipped the internal-user check for added accounts. The plan losing its marker is fixed at its cause instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
users/me marked the whole session modified to slide its expiry, so it saved the session data it loaded at the start of the request. A request that saved the session in the meantime, like starting "Add another user", lost its changes, and the flow then logged in without the add-user marker and signed out the first account. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… enabled Co-Authored-By: Claude Opus 5.5 <[email protected]>
dominic-r
merged commit Oct 8, 2026
0bbcf57
into
core/user-switch-keep-session
12 of 13 checks passed
✅ Deploy Preview for authentik-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
GirlBossRush
added a commit
that referenced
this pull request
Oct 14, 2026
… save (#26765) * core: keep the current login when adding a user after a stale session save The add-user marker lives in the session's flow plan. A concurrent request that saved an older copy of the session could drop it, so the login stage treated the new login as a plain one and login() deleted the previous user's session. When the brand has a user switch flow, logging in as another user now always keeps the current login as a switch target. * core: stop users/me from erasing session data saved by concurrent requests (#26790) * stages/user_login: only keep the current login for explicit user switches Treating every login on a brand with user switching as an add-user login changed what signing in as someone else means and skipped the internal-user check for added accounts. The plan losing its marker is fixed at its cause instead. Co-Authored-By: Claude Opus 5.5 <[email protected]> * core: extend session expiry from users/me without rewriting session data users/me marked the whole session modified to slide its expiry, so it saved the session data it loaded at the start of the request. A request that saved the session in the meantime, like starting "Add another user", lost its changes, and the flow then logged in without the add-user marker and signed out the first account. Co-Authored-By: Claude Opus 5.5 <[email protected]> * core: pin that a plain login replaces the session with user switching enabled Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]> * core: read expiry_extended directly in the session middleware (#26791) authentik's SessionStore is the only session engine, so the getattr fallback never applies. It only hid that save_expiry() right below is called without one. Co-authored-by: Claude Opus 5.5 <[email protected]> * stages/user_login: save only the last IP when a bound session changes IP The binding middleware set LAST_IP as a session key, which marked the session as modified. The full save at the end of the request then wrote back the session data loaded at its start, erasing anything a concurrent request saved in the meantime, like the user switching flow plan. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Dominic Roy <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
Details
This targets #26765's branch. It replaces that PR's fix with one for the cause of the flaky
102-user-switchingPlaywright test, and keeps the original login behavior.What was actually going wrong
GET /api/v3/core/users/me/setsession.modified = Trueon every call so the session's expiry would slide (commitf28509608b). The session middleware then saved the whole session it had loaded when the request started. When the user interface'susers/mecall overlappedPOST /api/v3/core/users/switch/("Add another user"),users/mewrote back its older copy and erased the flow plan that the switch request had just saved. The flow executor then planned a fresh authentication flow without the add-user marker, andlogin()replaced the first account's session. That is the intermittent "first account gets signed out".Problems fixed
users/menow callsSessionStore.extend_expiry(). When that is the only change to the session,SessionMiddlewareupdates justexpiresandlast_usedwith a singleUPDATEinstead of rewritingsession_data. A plan,SESSION_KEY_ADD_USER, or anything else a concurrent request saves is no longer lost tousers/me. The cookie is refreshed exactly as before, and a session deleted mid-request still raisesSessionInterrupted.main's rule: only explicit add-user and switch plans keep the current login.test_add_user_survives_concurrent_user_menow runs the add-user request while ausers/merequest has already loaded the session, then completes the login and checks both accounts stay live.Tests
test_add_user_survives_concurrent_user_mefails without the fix (KeyError: 'authentik/flows/plan', the plan was wiped) and passes with it.test_plain_login_replaces_session_with_switching_enabledfails with core: keep the current login when adding a user after a stale session save #26765'sstage.pyand passes on this branch, so the brand-wide fallback can't return unnoticed.test_user_me_extends_expirychecks thatusers/mestill movesexpiresforward and refreshes the session cookie.authentik/core,authentik/root,authentik/stages/user_login, andauthentik/flows: 583 passed. The one local failure istest_localesneeding themsgattribbinary, which is unrelated.Not covered
Any other request that really modifies the session while the switch request is in flight can still write back a stale copy, for example
BoundSessionMiddlewarerecording a new IP, or/popping the add-user key in another tab. Those are rare.users/mewas the frequent writer in this flow. A general fix would need per-key session writes and is out of scope here.🤖 Generated with Claude Code