Skip to content

flows: dedupe identical concurrent executor submissions - #25212

Open
APIUM wants to merge 4 commits into
goauthentik:mainfrom
APIUM:flows/dedup-duplicate-submissions
Open

APIUM wants to merge 4 commits into
goauthentik:mainfrom
APIUM:flows/dedup-duplicate-submissions

Conversation

@APIUM

@APIUM APIUM commented Aug 19, 2026

Copy link
Copy Markdown

Details

What does this PR change?

FlowExecutorView.post() deduplicates identical concurrent submissions. Each submission is fingerprinted (by session, stage binding, path, body) - the first request to win an atomic cache.add processes the stage and stores its response for 5s, and a duplicate waits for that response and replays it.

Why is this change needed?

iOS clients send every flow-executor request twice, concurrently (#25210). The duplicate consumes the TOTP code, so every successful iOS login emits a spurious login_failed, and on slow links users get locked out of their own valid codes.

How was this tested?

Six new unit tests in authentik/flows/tests/test_executor_dedup.py; the full authentik/flows/tests suite passes (123) against postgres.

I have also deployed it on my own instance and have been using it. iOS logins now don't fail, and I don get login_failed notifications on them or the successful ones like I used to.

Linked issues

closes #25210


Checklist

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

@APIUM
APIUM requested a review from a team as a code owner August 19, 2026 03:04
@netlify

netlify Bot commented Aug 19, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

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

@GirlBossRush

GirlBossRush commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

@APIUM Thanks for tracking this down and for the detailed write-up linking the WebKit bugs.

I've pushed a few changes on this branch:

  • Identical submissions now wait on pglock.advisory until the first one finishes. This is the same pattern we use for outgoing sync
  • The copied response used to drop Set-Cookie. If iOS delivered the copy, the browser kept the old session key and the user landed back at the start of the flow.
  • The first request saves its session before storing the redirect so a browser following the copied redirect finds the new session
  • Challenge bodies no longer go into the cache
  • Added a test checks that the stage ran once and that the duplicate got the same redirect

A wrong TOTP code can still log login_failed twice because only redirects are stored and duplicated GETs aren't covered here either. I've also added some protection from duplicate submission on the frontend in #27395

Could you try this on your iPhone setup and let me know how it goes?

@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.06173% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.28%. Comparing base (2e6d75d) to head (2fac33c).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
authentik/flows/views/executor.py 90.90% 5 Missing ⚠️
authentik/flows/tests/test_executor_dedup.py 97.19% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #25212      +/-   ##
==========================================
- Coverage   92.69%   92.28%   -0.41%     
==========================================
  Files        1198     1199       +1     
  Lines       81929    82091     +162     
  Branches     4686     4686              
==========================================
- Hits        75945    75759     -186     
- Misses       5908     6256     +348     
  Partials       76       76              
Flag Coverage Δ
conformance 30.66% <24.69%> (-0.34%) ⬇️
e2e 32.67% <25.30%> (-3.16%) ⬇️
integration 28.10% <8.02%> (-0.37%) ⬇️
rust 49.31% <ø> (ø)
unit 94.26% <95.06%> (+<0.01%) ⬆️
unit-migrate 94.25% <95.06%> (+<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.

@GirlBossRush
GirlBossRush force-pushed the flows/dedup-duplicate-submissions branch from 2fac33c to 6431fa5 Compare October 30, 2026 22:30
@APIUM

APIUM commented Oct 31, 2026

Copy link
Copy Markdown
Author

@APIUM Thanks for tracking this down and for the detailed write-up linking the WebKit bugs.

I've pushed a few changes on this branch:

  • Identical submissions now wait on pglock.advisory until the first one finishes. This is the same pattern we use for outgoing sync
  • The copied response used to drop Set-Cookie. If iOS delivered the copy, the browser kept the old session key and the user landed back at the start of the flow.
  • The first request saves its session before storing the redirect so a browser following the copied redirect finds the new session
  • Challenge bodies no longer go into the cache
  • Added a test checks that the stage ran once and that the duplicate got the same redirect

A wrong TOTP code can still log login_failed twice because only redirects are stored and duplicated GETs aren't covered here either. I've also added some protection from duplicate submission on the frontend in #27395

Could you try this on your iPhone setup and let me know how it goes?

Thanks @GirlBossRush, I’ve been running this today and it’s working well for me so far. Will continue to use and let you know how I go.

@netlify

netlify Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-storybook ready!

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

APIUM and others added 4 commits November 5, 2026 18:11
Some clients (iOS) send every flow-executor request twice. Processing
both submissions uses the TOTP code twice: the duplicate fails as a
replay, emits a login_failed event and can lock the user out.

Fingerprint each submission by (session, stage binding, path, body) and
select a single winner via an atomic cache.add; the duplicate waits for
the winner's response and replays it. Every dedup path fails open to
processing the request normally.
Replace cache polling with pglock.advisory. Store only redirects and carry
their cookies, including the rotated session cookie, to the replay. Save the
session before storing so a followed replay finds it.
Replace the mocked dedup tests with one customer path: a user whose TOTP
code is submitted twice at once is logged in once, with no login_failed.
@APIUM

APIUM commented Nov 5, 2026

Copy link
Copy Markdown
Author

This is still working well with my setup after about a week, no unexpected behavior.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

iOS clients send every flow-executor request twice - causes lockout

2 participants