Skip to content

web/flow: fix remember-me being cleared by CSRF token rotation - #25205

Merged
GirlBossRush merged 5 commits into
goauthentik:mainfrom
so-jelly:fix/remember-me-csrf-rotation
Oct 20, 2026
Merged

GirlBossRush merged 5 commits into
goauthentik:mainfrom
so-jelly:fix/remember-me-csrf-rotation

Conversation

@so-jelly

Copy link
Copy Markdown
Contributor

Details

The identification stage's "Remember me on this device" toggle never is cleared on login, the next visit the username is not prefilled and the toggle is unchecked.

RememberMeController derived a "session ID" from the first 8 characters of the authentik_csrf cookie, stored it alongside the username, and deleted the stored username whenever the two no longer matched. Django rotates the CSRF token on login, so that value can never match on the user's next visit.

Reproduction (no login required)

  1. Open a flow page with an identification stage that has enable_remember_me on.
  2. In the browser console: localStorage.setItem("authentik-remember-me-user", "[email protected]"); localStorage.setItem("authentik-remember-me-session", "OLDTOKEN").
  3. Reload — authentik-remember-me-user is deleted, the field is empty, the toggle unchecked.

Fix

The stored username is now cleared only by an explicit user action: switching the toggle off, or following the "Not you?" link, which already calls RememberMeStorage.reset() from FormStatic. The legacy authentik-remember-me-session key is deleted so state written by earlier versions is cleaned up.

Adds RememberMeController.unit.test.ts covering the behavior, including a regression case asserting the username survives a rotated CSRF cookie (fails on main, passes here).

Checklist

  • Local tests pass (cd web && pnpm test)
  • The code has been formatted (make lint-fix)

@so-jelly
so-jelly requested a review from a team as a code owner August 18, 2026 21:15
@netlify

netlify Bot commented Aug 18, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-integrations ready!

Name Link
🔨 Latest commit 3174f09
🔍 Latest deploy log https://app.netlify.com/projects/authentik-integrations/deploys/6a84cb78e38d670008f41591
😎 Deploy Preview https://deploy-preview-25205--authentik-integrations.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.

@netlify

netlify Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit 5756c9a
🔍 Latest deploy log https://app.netlify.com/projects/authentik-storybook/deploys/6a84cd17d4295c00088f1b1e
😎 Deploy Preview https://deploy-preview-25205--authentik-storybook.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.

@netlify

netlify Bot commented Aug 18, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit 3174f09
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6a84cb78a757c00008404705
😎 Deploy Preview https://deploy-preview-25205--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.

@so-jelly

Copy link
Copy Markdown
Contributor Author

Hello, there appears to be an approval to run the remaining CI workflows.

GirlBossRush and others added 4 commits October 20, 2026 03:48
Split #common/storage into an accessor and shared types, and require
storage keys to use the ak: prefix via a PersistenceKey type. Values
under the old remember-me and library view mode keys are moved to the
new keys on load, so returning users keep their remembered username and
layout. The migrations are marked for removal in 2027.2 (goauthentik#27036).

Remove ShowHintController, which has had no users since goauthentik#21781.
The remembered username was keyed to a session ID derived from the CSRF
token, and cleared whenever the two didn't match. Django rotates the
CSRF token on every successful login, so the check failed on every
later visit and the username was always forgotten. Drop the check, so
the username is only cleared by switching the toggle off or following
"Not you?", and discard the session ID left by earlier versions.

Co-authored-by: Shawn O'Dell <[email protected]>
The remember-me input listener was only attached from the toggle's change
handler, so a returning user, who arrives with the switch already checked,
never had it bound. A different user on the same device could type and
submit their own username without it ever reaching localStorage, leaving
the previous username prefilled forever, and auto-submitted in
identification-only flows.

Track whether the feature is on, seeded from the persisted value, and
reconcile the listener when the controller connects and after each update.
The stage adds the controller after it has rendered, so a further update
isn't guaranteed. Cancel a pending keystroke write when the listener is
detached, so switching the toggle off can't be undone by a write queued in
the same frame. Disconnect the controller before the stage removes it,
since removeController doesn't notify it and the listener would otherwise
keep recording after the server turns remember-me off.

Co-authored-by: Shawn O'Dell <[email protected]>
canAutoSubmit only checked whether a username was remembered when the
page loaded, so a returning user who switched the toggle off was kept
from being auto-submitted only by the one-shot attempt counter. Also
require the feature to still be on. Checking only the live toggle state
would instead auto-submit first-time visitors as soon as they opted in.
@GirlBossRush
GirlBossRush force-pushed the fix/remember-me-csrf-rotation branch from 6659142 to 3ad3964 Compare October 20, 2026 02:50
@GirlBossRush GirlBossRush self-assigned this Oct 20, 2026
@GirlBossRush GirlBossRush added the area:frontend Features or issues related to the browser, TypeScript, Node.js, etc label Oct 20, 2026
@codecov

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.32%. Comparing base (a749575) to head (1f3d548).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #25205      +/-   ##
==========================================
- Coverage   92.36%   92.32%   -0.04%     
==========================================
  Files        1188     1188              
  Lines       80005    80005              
  Branches     4351     4351              
==========================================
- Hits        73893    73867      -26     
- Misses       6046     6072      +26     
  Partials       66       66              
Flag Coverage Δ
conformance 32.29% <ø> (+<0.01%) ⬆️
e2e 36.99% <ø> (+<0.01%) ⬆️
integration 28.68% <ø> (-0.49%) ⬇️
rust 44.42% <ø> (ø)
unit 94.01% <ø> (+<0.01%) ⬆️
unit-migrate 94.01% <ø> (+<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.

The API answers before the worker has applied the default blueprints.
Until then `/` redirects to an authentication flow that doesn't exist
yet and 404s, so the availability check could fail on a slow start and
skip the whole suite. Poll until the redirect chain resolves, and run
the setup steps serially so the login step waits on it too.
@GirlBossRush
GirlBossRush merged commit 2eafedc into goauthentik:main Oct 20, 2026
140 checks passed
kensternberg-authentik added a commit that referenced this pull request Nov 5, 2026
* main: (21 commits)
  policies: fix warning from setting non-string tracing data (#27062)
  root: annotate hot paths (#27052)
  website/docs: contributing: add guidelines for vendor contributions (#27032)
  providers/saml: Add ability to select encryption algorithm (#27009)
  lib: set postgres timezone on connection (#27053)
  core: add postgres connection info (#27024)
  ci: fix cargo deny for basic-toml (#27054)
  web/elements: keep ak-array-input edits through form submission (#27045)
  enterprise: optimize middleware (#27015)
  core: bump goauthentik/platform-ssh from 26.04-ak-0.72.0 to 26.04-ak-0.72.1 in /tests/e2e (#27038)
  core: bump ruff from 0.16.10 to 0.17.0 (#27044)
  core: bump sentry-sdk from 2.71.0 to 2.72.0 (#27043)
  core: bump django-postgres-extra from 3.0.0 to 3.0.1 (#27042)
  core: bump python-kadmin-rs from 0.7.4 to 0.7.5 (#27040)
  core: bump goauthentik/selenium from 152.0-ak-0.72.0 to 152.0-ak-0.72.1 in /tests/e2e (#27039)
  core: bump aiohttp from 3.14.3 to 3.14.4 (#27034)
  web/flow: fix remember-me being cleared by CSRF token rotation (#25205)
  web/theme: Remove the categories build from the theme (#26982)
  core: bump library/golang from `2f84bc9` to `4766793` in /lifecycle/container (#26996)
  providers/saml: verify logoutrequest/response signatures (#26534)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:frontend Features or issues related to the browser, TypeScript, Node.js, etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants