Repository navigation
Conversation
95b1c5d to
dcc9cdb
Compare
|
Updated the PR: some existing tests in the new test framework assumed one verification e-mail per login, which no longer holds with the per-user resend cooldown. I adapted them:
I also merged the cooldown check into the main Locally (Windows, JDK 21) these classes pass, except |
|
Follow-up: CI on my fork is green for this exact commit (dcc9cdb), including the Base1–Base4 test suites (Base2 and Base3 previously failed): https://github.com/julioo19/keycloak/actions?query=branch%3Aci-check-54821 So |
Closes keycloak#54821 Signed-off-by: Julio Cesar Montalvan <110637361+julioo19@users.noreply.github.com>
dcc9cdb to
1b4ba23
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Concurrent new authentication sessions for the same user can both pass the cooldown check and send verification emails. The cache read does not atomically reserve the cooldown, and the unconditional write is deferred until the Infinispan transaction commits.
1 open issue
Review effort: Balanced
| if (!Objects.equals(authSession.getAuthNote(Constants.VERIFY_EMAIL_KEY), email) && !(isCurrentActionTriggeredFromAIA(context) && isChallenge)) { | ||
| if (!Objects.equals(authSession.getAuthNote(Constants.VERIFY_EMAIL_KEY), email) | ||
| && !(isCurrentActionTriggeredFromAIA(context) && isChallenge) | ||
| && remaining == null) { |
There was a problem hiding this comment.
Thanks Copilot, this is correct: two concurrent requests can both read no cooldown before either write is committed (the write is deferred until the Infinispan transaction commits), so both would send an e-mail.
I left it out of this PR on purpose:
- The same non-atomic read-then-write already exists in
processAction()(the resend link); this PR doesn't introduce it, it only makesprocess()honor the existing per-user cooldown for new authentication sessions. - In the discussion on VERIFY_EMAIL resend cooldown is not applied on the challenge path: every new authentication session sends a verification e-mail #54821, the issue author suggested treating concurrency as a separate change.
- Reserving the cooldown atomically (
putIfAbsent) is tracked in VERIFY_EMAIL cooldown allows concurrent requests to send multiple emails #55405 and implemented in Admit a single concurrent verification email send per cooldown window #55511.
That said, it's the maintainers' call: I'm happy to include an atomic reservation here, or to align with #55511 in whichever order you prefer to merge them.

Closes #54821
VerifyEmail.process()sent the verification e-mail whenever the authentication session had noVERIFY_EMAIL_KEYnote, which is the case for every new session. The resend cooldown is stored per user, but it was only checked inprocessAction()(the resend link).This change checks the cooldown in
process()before sending, as an extra condition of the existingif. While it is active, the page is rendered without sending an e-mail and without setting the note, so a refresh after the cooldown expires sends at most one e-mail (as discussed in the issue).Tests: added
verifyEmailNewSessionRespectsResendCooldowntoRequiredActionEmailVerificationTest. It fails without the fix (two e-mails instead of one) and passes with it.Since the old testsuite is deprecated, I followed
testsuite/DEPRECATED.md, which allows a limited number of changes to existing tests, mainly to add test cases when resolving bugs, and does not allow new files. This adds one test method and no new files. Happy to move it to the new Test Framework if you prefer though.Updated tests
Some tests in the new test framework assumed one verification e-mail per login, which no longer holds with the per-user cooldown:
RegisterWithEmailVerificationTest,OrganizationPostBrokerMembershipTest:@InjectTimeOffSet(enableForCaches = true)+timeOffSet.set(40)before the step that expects a new e-mail.AbstractSslEmailTest,EmailPlainAuthTest: per-method user (LifeCycle.METHOD) so each test starts without a cooldown.CI on my fork is green for this commit: https://github.com/julioo19/keycloak/actions?query=branch%3Aci-check-54821
Docs: no option was added or changed, and I found no hand-written docs describing this behavior.
AI usage: I used Claude to help me understand the code and the project workflow, to review my changes, and for suggestions on the test outline, the test adaptations, some code comments, and the wording of this PR. I wrote the fix and the test logic myself and ran the tests locally.