fix(web): prevent JWT session fixation via crafted URL fragments#335
Conversation
…on fixation An attacker could craft /login#token=ATTACKER_JWT to fixate a victim's session, since token extraction ran on every route before the public route check. The backend OAuth callback only ever redirects to /#token=<jwt>, so restricting extraction to to.path === "/" closes the attack surface with no impact on the legitimate OAuth flow. Co-Authored-By: Claude <noreply@anthropic.com>
Eliminates the duplicated "#token=" magic string used in both the startsWith check and the slice call. Co-Authored-By: Claude <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughRestricts JWT token extraction from URL hashes to the root path ("/") only, introducing a Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
to.path === "/"only — the sole legitimate OAuth callback target/login#token=ATTACKER_JWTto overwrite a victim's sessionTOKEN_HASH_PREFIXconstant to eliminate the duplicated"#token="magic stringSecurity context
The backend OAuth callback always redirects to
/#token=<jwt>. Token extraction on any other path is illegitimate. Before this fix, visiting/login#token=ATTACKER_JWTwould silently store the attacker's JWT before the public-route check could short-circuit.Test plan
npm run build --prefix web/frontendpasses (type-check + build)/api/auth/callback→/#token=...→/guilds) still works end-to-end/login#token=fakeno longer stores the token in the auth store🤖 Generated with Claude Code
Summary by CodeRabbit