Skip to content

web/flows: fix race condition in continuous login and support source stages in authentication flows - #23049

Merged
BeryJu merged 11 commits into
goauthentik:mainfrom
ryanpesek:fix-continuous-login
Jun 26, 2026
Merged

BeryJu merged 11 commits into
goauthentik:mainfrom
ryanpesek:fix-continuous-login

Conversation

@ryanpesek

Copy link
Copy Markdown
Contributor

Summary

Fix continuous login multi-tab coordination so tabs resume only after the authentication flow has fully completed, and preserve each tab’s original SP-initiated SAML request.
This also makes continuous login work correctly when the authentication flow contains intermediate source stages, such as an OIDC source step.

Details

This change fixes two related continuous-login issues:

  • SP-initiated SAML tabs could race with each other because the active flow/authorization plan is shared by the browser session.
  • Intermediate redirects, such as source-stage redirects to an external IdP, could be mistaken for final login completion.
    The fix introduces an explicit final_redirect marker on redirect challenges. The frontend now only starts multi-tab resume orchestration when a redirect is known to be final. Intermediate redirects, including source-stage redirects, continue normally without resuming other tabs.
    For SP-initiated SAML Redirect binding, the original SAML request URL is preserved as the flow next URL. This keeps each tab tied to its own SAMLRequest and RelayState when it resumes after another tab completes authentication.
    The tab coordination logic was also hardened:
  • Each resumed tab gets a unique resume ID.
  • Exit events must match the expected tab and resume ID.
  • Same-origin authentik navigations suppress premature tab-exit signaling.
  • Final foreign redirects signal completion.
  • A bounded wait prevents one stuck tab from deadlocking the leader tab indefinitely.

Behavior Changes

  • Continuous login no longer treats all foreign redirects as “login complete.”
  • Source-stage redirects are treated as intermediate redirects.
  • Other tabs are resumed only after the final redirect out of the completed authentication flow.
  • SP-initiated SAML Redirect flows preserve the original request/RelayState per tab.
  • Continuous login is more robust against stale or out-of-order tab exit events.

Testing

  • Added/updated flow executor tests for final redirect challenges.
  • Added source-stage coverage to ensure source-stage redirects are not marked final.
  • Added SAML Redirect binding coverage to ensure the original SAML URL is preserved.
  • Ran SAML provider tests.
  • Ran frontend lint/format/type checks.
  • Ran frontend unit tests.

Checklist

  • The project has been linted, built, and tested (make all)
  • The documentation has been updated and formatted (make docs)

@ryanpesek
ryanpesek requested review from a team as code owners June 15, 2026 03:24
@netlify

netlify Bot commented Jun 15, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit 18aa178
🔍 Latest deploy log https://app.netlify.com/projects/authentik-storybook/deploys/6a3e7e8b49388b0008a1ddc4
😎 Deploy Preview https://deploy-preview-23049--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 Jun 15, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit 18aa178
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6a3e7e8b15e2fb0008878a34
😎 Deploy Preview https://deploy-preview-23049--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 Jun 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.26%. Comparing base (b2738d8) to head (5a64d05).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #23049      +/-   ##
==========================================
- Coverage   93.28%   93.26%   -0.03%     
==========================================
  Files        1037     1037              
  Lines       60556    60610      +54     
  Branches      400      400              
==========================================
+ Hits        56490    56525      +35     
- Misses       4066     4085      +19     
Flag Coverage Δ
conformance 36.32% <11.86%> (-0.03%) ⬇️
e2e 41.54% <15.25%> (-0.03%) ⬇️
integration 32.29% <10.16%> (-0.51%) ⬇️
rust 0.00% <ø> (ø)
unit 92.34% <98.30%> (+0.07%) ⬆️
unit-migrate 92.37% <98.30%> (+0.07%) ⬆️

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.

@netlify

netlify Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-integrations ready!

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

@GirlBossRush
GirlBossRush force-pushed the fix-continuous-login branch from 7bd8c94 to 64f7e09 Compare June 23, 2026 15:09
Drop the unused isForeignURL() helper from RedirectStage (its only
caller was replaced by the finalRedirect gate) and the write-only
exitedTabIDs map from Broadcast (exit tracking now flows through
AKMultiTabExitEvent).
The continuous-login branch of SAMLFlowFinalView built the
RedirectChallenge with data= and handed it straight to
HttpChallengeResponse, which reads .data. DRF raises AssertionError
("must call .is_valid()") when a serializer is given data= without
validation, so SP-initiated SAML Redirect-binding logins 500'd whenever
the flows_continuous_login flag was enabled. Use instance= to serialize
the value directly, matching the other RedirectChallenge call sites.

Add a regression test that drives the SP-initiated Redirect flow through
the executor to SAMLFlowFinalView under continuous login and asserts a
final redirect challenge is returned. Also fix the adjacent
resume-url test, which created a second Application for a provider that
already has one (violating the unique provider constraint).
@GirlBossRush
GirlBossRush requested a review from BeryJu June 23, 2026 18:40
@GirlBossRush GirlBossRush added area:frontend Features or issues related to the browser, TypeScript, Node.js, etc area:backend labels Jun 23, 2026
@github-project-automation github-project-automation Bot moved this from Todo to In Progress in authentik Core Jun 26, 2026
@BeryJu
BeryJu merged commit 4296064 into goauthentik:main Jun 26, 2026
105 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in authentik Core Jun 26, 2026
@rissson rissson added backport/version-2026.2 Add this label to PRs to backport changes to version-2026.2 backport/version-2026.5 Add this label to PRs to backport changes to version-2026.5 labels Jun 26, 2026
GirlBossRush added a commit that referenced this pull request Jun 30, 2026
…stages in authentication flows (cherry-pick #23049 to version-2026.2)

Backport of #23049, rebuilt from the final merged state on main
(4296064) rather than the early PR revision the previous attempt was
based on.

Adaptations for version-2026.2:
- FlowMultitabController logic ported inline into FlowExecutor's
  ak-multitab-continue listener (2026.2 lacks the controllers refactor),
  keeping the blank://blank app-hiding guard still used in 2026.2.
- test_auth_n_request setUp creates the test-app Application (main
  already had it).
- Generated API clients are produced from schema.yml at release time;
  only the schema contract is committed (2026.2 tracks no client-*).

Co-Authored-By: Playpen Agent <[email protected]>
gergosimonyi pushed a commit that referenced this pull request Jul 3, 2026
…stages in authentication flows (cherry-pick #23049 to version-2026.2) (#23557)

Backport of #23049, rebuilt from the final merged state on main
(4296064) rather than the early PR revision the previous attempt was
based on.

Adaptations for version-2026.2:
- FlowMultitabController logic ported inline into FlowExecutor's
  ak-multitab-continue listener (2026.2 lacks the controllers refactor),
  keeping the blank://blank app-hiding guard still used in 2026.2.
- test_auth_n_request setUp creates the test-app Application (main
  already had it).
- Generated API clients are produced from schema.yml at release time;
  only the schema contract is committed (2026.2 tracks no client-*).

Co-authored-by: Playpen Agent <[email protected]>
GirlBossRush added a commit that referenced this pull request Jul 9, 2026
…stages in authentication flows (cherry-pick #23049 to version-2026.5) (#23558)

Clean cherry-pick of #23049 (4296064) onto version-2026.5; no
adaptations were needed. 2026.5 already has the flow controllers
refactor, the blank://blank app-hiding migration, and the generated
API clients tracked in-repo, so the squash diff applied verbatim.

(cherry picked from commit 4296064)

Co-authored-by: Ryan Pesek <[email protected]>
Co-authored-by: Playpen Agent <[email protected]>
Co-authored-by: Connor Peshek <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend area:frontend Features or issues related to the browser, TypeScript, Node.js, etc backport/version-2026.2 Add this label to PRs to backport changes to version-2026.2 backport/version-2026.5 Add this label to PRs to backport changes to version-2026.5

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants