Skip to content
This repository was archived by the owner on Apr 6, 2026. It is now read-only.

fix(web): prevent JWT session fixation via crafted URL fragments#335

Merged
karaktaka merged 2 commits into
mainfrom
fix/jwt-session-fixation
Mar 15, 2026
Merged

fix(web): prevent JWT session fixation via crafted URL fragments#335
karaktaka merged 2 commits into
mainfrom
fix/jwt-session-fixation

Conversation

@karaktaka
Copy link
Copy Markdown
Contributor

@karaktaka karaktaka commented Mar 15, 2026

Summary

  • Restricts JWT token extraction from URL fragments to to.path === "/" only — the sole legitimate OAuth callback target
  • Prevents session fixation attacks where an attacker crafts /login#token=ATTACKER_JWT to overwrite a victim's session
  • Extracts TOKEN_HASH_PREFIX constant to eliminate the duplicated "#token=" magic string

Security 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_JWT would silently store the attacker's JWT before the public-route check could short-circuit.

Test plan

  • npm run build --prefix web/frontend passes (type-check + build)
  • OAuth flow (/api/auth/callback/#token=.../guilds) still works end-to-end
  • Visiting /login#token=fake no longer stores the token in the auth store

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • JWT token extraction is now restricted to the root path only and requires a specific token hash prefix. This prevents unintended token processing in other application areas, enhancing security.

karaktaka and others added 2 commits March 15, 2026 01:53
…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>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 108a6530-d525-4478-9943-52b249790d1f

📥 Commits

Reviewing files that changed from the base of the PR and between 1bd8d4c and 831ce23.

📒 Files selected for processing (1)
  • web/frontend/src/router/index.ts

📝 Walkthrough

Walkthrough

Restricts JWT token extraction from URL hashes to the root path ("/") only, introducing a TOKEN_HASH_PREFIX constant for pattern matching. Previously, token extraction occurred anywhere in the application when "#token=" appeared in the hash; now it's gated behind the root-path condition.

Changes

Cohort / File(s) Summary
JWT Token Extraction Restriction
web/frontend/src/router/index.ts
Introduces TOKEN_HASH_PREFIX constant and restricts JWT token extraction to root path ("/") with hash prefix validation. Token extraction and hash-clearing redirect now gated behind root-path condition.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main security fix: preventing JWT session fixation attacks via malicious URL fragments.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/jwt-session-fixation
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@karaktaka karaktaka merged commit a651e92 into main Mar 15, 2026
9 checks passed
@karaktaka karaktaka deleted the fix/jwt-session-fixation branch March 15, 2026 01:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant