Skip to content

core: keep the current login when adding a user after a stale session save - #26765

Merged
GirlBossRush merged 5 commits into
mainfrom
core/user-switch-keep-session
Oct 14, 2026
Merged

GirlBossRush merged 5 commits into
mainfrom
core/user-switch-keep-session

Conversation

@GirlBossRush

@GirlBossRush GirlBossRush commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Details

This PR prevents "Add another user" from signing out the first account. I encountered this while testing the Playwright 102-user-switching test where it'd failed intermittently (1 in 3–8 runs). This change appears to eliminate the flakiness.

  • A concurrent request could overwrite the session's flow plan and erase the add-user marker. Then login() deleted the first user's session.
  • users/me marked the session as modified on every call to extend its expiry, so the middleware wrote the whole session back, including the stale copy of the flow plan it loaded at the start of the request. It now saves only expires and last_used.
  • Session binding had the same problem: when a bound session's IP changed, the middleware set last_ip as a session key, which caused the same full write-back. It now updates only the last_ip column.
  • Signing in as a different user without "Add another user" still replaces the current login. test_plain_login_replaces_session_with_switching_enabled covers that.

@GirlBossRush
GirlBossRush requested a review from a team as a code owner October 8, 2026 04:06
@netlify

netlify Bot commented Oct 8, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit 61361f7
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6ac716c532018e00085d7796
😎 Deploy Preview https://deploy-preview-26765--authentik-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.42%. Comparing base (c3f92b6) to head (1b69499).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
authentik/core/sessions.py 90.90% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #26765   +/-   ##
=======================================
  Coverage   92.42%   92.42%           
=======================================
  Files        1179     1179           
  Lines       78482    78551   +69     
  Branches     4129     4129           
=======================================
+ Hits        72534    72604   +70     
+ Misses       5882     5881    -1     
  Partials       66       66           
Flag Coverage Δ
conformance 32.67% <20.00%> (-0.02%) ⬇️
e2e 37.42% <20.00%> (-0.02%) ⬇️
integration 29.51% <10.66%> (-0.02%) ⬇️
rust 46.45% <ø> (ø)
unit 93.85% <98.66%> (+<0.01%) ⬆️
unit-migrate 93.85% <98.66%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Playwright e2e

Download this run's HTML report and traces, then open the report:

gh run download 37826324496 -D playwright-artifacts
npx playwright show-report playwright-artifacts/playwright-report

Installation instructions

Instructions for docker-compose

Add the following block to your .env file:

AUTHENTIK_IMAGE=ghcr.io/goauthentik/dev-server
AUTHENTIK_TAG=gh-1b69499579761331e1362479dcd0059bdda2bd4e
AUTHENTIK_OUTPOSTS__CONTAINER_IMAGE_BASE=ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s

Afterwards, run the upgrade commands from the latest release notes.

Instructions for Kubernetes

Add the following block to your values.yml file:

authentik:
    outposts:
        container_image_base: ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s
global:
    image:
        repository: ghcr.io/goauthentik/dev-server
        tag: gh-1b69499579761331e1362479dcd0059bdda2bd4e

Afterwards, run the upgrade commands from the latest release notes.

… 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.
@GirlBossRush
GirlBossRush force-pushed the core/user-switch-keep-session branch from 61361f7 to 7b056a4 Compare October 8, 2026 16:16
…uests (#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]>
dominic-r and others added 2 commits October 8, 2026 14:41
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]>
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]>
@github-project-automation github-project-automation Bot moved this from Needs review to In Progress in authentik Core Oct 14, 2026
@GirlBossRush
GirlBossRush merged commit d57d81e into main Oct 14, 2026
147 checks passed
@GirlBossRush
GirlBossRush deleted the core/user-switch-keep-session branch October 14, 2026 23:35
@github-project-automation github-project-automation Bot moved this from In Progress to Done in authentik Core Oct 14, 2026
kensternberg-authentik added a commit that referenced this pull request Oct 15, 2026
* main: (86 commits)
  ci: switch version bump to action, like platform repo (#26949)
  core, web: update translations (#26940)
  ci: bump actions/create-github-app-token from 3.2.0 to 3.3.0 (#26946)
  ci: bump taiki-e/install-action from 2.87.27 to 2.87.28 in /.github/actions/setup (#26947)
  core: bump hyper-unix-socket from 0.6.1 to 0.7.0 (#26945)
  core: bump goauthentik/selenium from 152.0-ak-0.71.0 to 152.0-ak-0.72.0 in /tests/e2e (#26943)
  core: bump goauthentik/platform-ssh from 26.04-ak-0.71.0 to 26.04-ak-0.72.0 in /tests/e2e (#26944)
  core: keep the current login when adding a user after a stale session save (#26765)
  flows: fix blip of un-templated flow title placeholder (#26905)
  website/docs: Version 2026.8.4 Release Notes (cherry-pick #26934 to main) (#26939)
  core: bump rust-toolchain from 1.98.1 to 1.99.0 (#26634)
  stages/authenticator_validate: enforce code device restrictions (#26779)
  website/docs: Expand docs on aws installation (#26812)
  web: Add alert when JavaScript is disabled. (#26921)
  website: remove the docs glossary (#26930)
  core: bump axllent/mailpit from v1.31.4 to v1.31.5 in /tests/e2e (#26907)
  core: bump astral-sh/uv from 0.13.0 to 0.13.1 in /lifecycle/container (#26909)
  core: bump serde_json from 1.0.151 to 1.0.154 (#26911)
  core: bump the types group with 2 updates (#26912)
  core: bump aws-lc-rs from 1.18.1 to 1.18.2 (#26913)
  ...
kensternberg-authentik added a commit that referenced this pull request Oct 19, 2026
* main: (144 commits)
  ci: switch version bump to action, like platform repo (#26949)
  core, web: update translations (#26940)
  ci: bump actions/create-github-app-token from 3.2.0 to 3.3.0 (#26946)
  ci: bump taiki-e/install-action from 2.87.27 to 2.87.28 in /.github/actions/setup (#26947)
  core: bump hyper-unix-socket from 0.6.1 to 0.7.0 (#26945)
  core: bump goauthentik/selenium from 152.0-ak-0.71.0 to 152.0-ak-0.72.0 in /tests/e2e (#26943)
  core: bump goauthentik/platform-ssh from 26.04-ak-0.71.0 to 26.04-ak-0.72.0 in /tests/e2e (#26944)
  core: keep the current login when adding a user after a stale session save (#26765)
  flows: fix blip of un-templated flow title placeholder (#26905)
  website/docs: Version 2026.8.4 Release Notes (cherry-pick #26934 to main) (#26939)
  core: bump rust-toolchain from 1.98.1 to 1.99.0 (#26634)
  stages/authenticator_validate: enforce code device restrictions (#26779)
  website/docs: Expand docs on aws installation (#26812)
  web: Add alert when JavaScript is disabled. (#26921)
  website: remove the docs glossary (#26930)
  core: bump axllent/mailpit from v1.31.4 to v1.31.5 in /tests/e2e (#26907)
  core: bump astral-sh/uv from 0.13.0 to 0.13.1 in /lifecycle/container (#26909)
  core: bump serde_json from 1.0.151 to 1.0.154 (#26911)
  core: bump the types group with 2 updates (#26912)
  core: bump aws-lc-rs from 1.18.1 to 1.18.2 (#26913)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants