Repository navigation
Description
Before reporting an issue
- I have read and understood the above terms for submitting issues, and I understand that my issue may be closed without action if I do not follow them.
Area
authentication
Bug Description
The VERIFY_EMAIL resend cooldown does not reliably prevent concurrent requests from sending multiple verification emails for the same user.
The explicit resend flow checks the cooldown and creates the cooldown entry as separate operations:
processAction()checks the existing cooldown.- If no cooldown is found, it calls
process(). process()creates the cooldown entry and sends the email.
Two requests arriving at nearly the same time can both complete the check before either creates the cooldown entry. Both requests may then send an email.
This is a follow-up to:
- VERIFY_EMAIL resend cooldown is not applied on the challenge path: every new authentication session sends a verification e-mail #54821 (comment)
- Apply VERIFY_EMAIL resend cooldown on new authentication sessions #54947
The pull request addresses sequential fresh-session sends, but intentionally leaves concurrent admission as a separate issue.
The check-then-write sequence is present on main at commit 994ee7e.
Version
26.6.4
Regression
- The issue is a regression
Expected behavior
For a single user, only one verification email request should be admitted during the cooldown period, even when requests arrive concurrently.
This should apply when requests are made through:
- Two concurrent explicit resend requests.
- Two concurrent automatic verification email sends.
- An automatic send and an explicit resend at the same time.
- Different Keycloak nodes.
Requests for different users should remain independent.
After the cooldown expires, a new request should be allowed to send another verification email.
Actual behavior
Reading the cooldown entry and creating it are separate operations.
Multiple requests can therefore observe that no cooldown exists before any request creates it. Each request may then send a verification email.
How to Reproduce?
- Configure Keycloak with a working SMTP server.
- Enable email verification for the realm.
- Create a user with:
- A valid email address.
- A known password.
emailVerified=false.
- Sign in and open the email verification page in two or more independent sessions.
- Wait until any existing resend cooldown has expired, then record the current number of received emails.
- Send explicit resend requests from those sessions at nearly the same time.
- Inspect the recipient mailbox or SMTP server.
Depending on request timing, two or more requests can pass the cooldown check and each send a verification email.
A deterministic integration test could synchronize two requests after they read the cooldown entry but before either creates it.
The test should also be repeated with two Keycloak nodes, sending one request to each node.
Anything else?
Relevant code:
A possible solution is to use one shared atomic per-user admission operation for both automatic sends and explicit resends. SingleUseObjectProvider.putIfAbsent() may provide the required operation, subject to verifying its behavior with both embedded and remote Infinispan.
Suggested tests:
- Two concurrent explicit resend requests for the same user.
- An automatic send racing an explicit resend.
- Requests handled by different Keycloak nodes.
- Concurrent requests for different users.
- Retry after the cooldown expires.
The behavior after EmailException also needs an explicit policy:
- Keeping the cooldown protects the rate limit when SMTP delivery is uncertain, but delays retry after a confirmed failure.
- Removing the cooldown permits immediate retry, but SMTP may already have accepted the first email.
Metadata
Metadata
Assignees
Labels
Type
Fields
Projects
- StatusShow more project fieldsOpen
Activity
Admit a single concurrent verification email send per cooldown window
Admit a single concurrent verification email send per cooldown window