Skip to content

Fix weak CSRF nonce in CSRF Challenge Six Target - #259

Open
JBHook wants to merge 2 commits into
OWASP-CTF:dc34-ctffrom
JBHook:fix/csrf6-weak-nonce
Open

JBHook wants to merge 2 commits into
OWASP-CTF:dc34-ctffrom
JBHook:fix/csrf6-weak-nonce

Conversation

@JBHook

@JBHook JBHook commented Aug 9, 2026

Copy link
Copy Markdown

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:check clean, full test suite passes
  • Live-validated: brute-forcing the old 3-value hardcoded array no longer succeeds.

🤖 Generated with Claude Code

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>
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

🏆 Security Shepherd — CTF Patch Score

░░░░░░░░░░░░░░░░░░░░  0 / 79 pts  (0%)

0 / 40 challenges patched

Per-challenge detail is withheld — it would reveal the rubric.

Commit: 47cef74 · scoring run

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant