Repository navigation
Conversation
validateAndConsume read the code, checked revoked/expiresAt in Java, then issued an unconditional UPDATE. Two concurrent GET /user/login/otc requests for the same code could both pass the check and both receive the JWT. Move the revoked and expiry conditions into the UPDATE and treat the code as redeemed only when this call updated the row.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
OneTimeCodeService.validateAndConsumereads the code, checksrevokedandexpiresAtin Java, then issues an unconditionalUPDATE ... set revoked = true. Two concurrentGET /user/login/otc?code=...requests for the same code can both readrevoked = falseand both receive the pre-minted JWT. That breaks the single-use guarantee of one-time codes.Fix
OneTimeCodeRepository.revokeByCodewithconsumeByCode(code, now), a conditionalUPDATEthat only matches rows that are still unrevoked and unexpired, and returns the updated row count.validateAndConsumetreats the code as redeemed only when this call updated exactly one row. Only then does it load the entity and return the JWT.Tests
Added
OneTimeCodeServiceTest. It covers the successful consume and the case where the conditional update matches no row, where the JWT must not be read. I couldn't build locally (no JDK 21 compiler available), so CI is the first compile and test run for this change.