Repository navigation
Admit a single concurrent verification email send per cooldown window #55511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f3550be
49ad4e4
9789a2a
5424263
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,11 +136,15 @@ private void process(RequiredActionContext context, boolean isChallenge) { | |
|
|
||
| // Do not allow resending e-mail by simple page refresh, i.e. when e-mail sent, it should be resent properly via email-verification endpoint | ||
| if (!Objects.equals(authSession.getAuthNote(Constants.VERIFY_EMAIL_KEY), email) && !(isCurrentActionTriggeredFromAIA(context) && isChallenge)) { | ||
| // Adding the cooldown entry first to prevent concurrent operations | ||
| EmailCooldownManager.addCooldownEntry(context, EMAIL_RESEND_COOLDOWN_KEY_PREFIX); | ||
| authSession.setAuthNote(Constants.VERIFY_EMAIL_KEY, email); | ||
| EventBuilder event = context.getEvent().clone().event(EventType.SEND_VERIFY_EMAIL).detail(Details.EMAIL, email); | ||
| challenge = sendVerifyEmail(context, event); | ||
| // Atomically claim the cooldown slot so that concurrent requests cannot each send a verification email | ||
| if (EmailCooldownManager.addCooldownEntryIfAbsent(context, EMAIL_RESEND_COOLDOWN_KEY_PREFIX)) { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair point. The model test guards the putIfAbsent primitive rather than VerifyEmail's use of it, so it would not catch a revert of the gating change here. A deterministic test that races an automatic send against an explicit resend through VerifyEmail needs a way to hold one request between the cooldown read and the atomic claim, and the tests/ harness drives requests through a single browser session with no such hook, so it cannot be made reliable without a small test seam in the challenge path. I would rather not add that seam unilaterally. If a maintainer has a preferred approach (a seam in VerifyEmail, or a different level at which to assert the single send), I am happy to add it. Leaving this open for that steer. |
||
| authSession.setAuthNote(Constants.VERIFY_EMAIL_KEY, email); | ||
| EventBuilder event = context.getEvent().clone().event(EventType.SEND_VERIFY_EMAIL).detail(Details.EMAIL, email); | ||
| challenge = sendVerifyEmail(context, event); | ||
| } else { | ||
| // A concurrent request already claimed the slot; re-render the page without sending another email | ||
| challenge = loginFormsProvider.createResponse(UserModel.RequiredAction.VERIFY_EMAIL); | ||
| } | ||
| } else { | ||
| challenge = loginFormsProvider.createResponse(UserModel.RequiredAction.VERIFY_EMAIL); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.