Conversation
The nonce was random.nextInt(3) used as an index into a 3-element array, so only 3 possible values ever existed - an attacker could brute-force a valid nonce in at most 3 tries without ever touching the victim's session. Switched to utils.Hash.randomString(), matching the real-random pattern already used correctly in CsrfChallengeTargetFour/Seven. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
🏆 Security Shepherd — CTF Patch Score0 / 40 challenges patched
Commit: No points yet — this commit didn't solve any challenges, so there's nothing on the leaderboard for it. Patch a vulnerability and push again! 💪 |
The weak-nonce fix in this branch only addressed CsrfChallengeTargetSix's
own token generation (random.nextInt(3) -> Hash.randomString()), but left
CsrfChallengeSixGetToken untouched: it took the userId to look up from a
request parameter instead of the caller's own session, and matched it with
LIKE (wildcard metacharacters unescaped) instead of an exact match - letting
any user fetch any other user's real CSRF token directly, completely
defeating the point of the token being unpredictable. Same bug class,
same fix, as the equivalent endpoint already fixed for CSRF Challenge Seven.
Scoped the lookup to the caller's own session userId
(ses.getAttribute("userStamp")) and switched LIKE to an exact match.
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.
Summary
The nonce was
random.nextInt(3)used as an index into a 3-element hardcoded array, so only 3 possible values ever existed.Fix
Switched to
utils.Hash.randomString().Test plan
mvn compile,mvn spotless:checkclean, full test suite passes🤖 Generated with Claude Code