fix(security): sanitize API redirect_path on login/register (open-redirect) - #14
Conversation
…irect) login and register pushed the API-supplied redirect_path straight to the router, allowing open redirects (//evil.com, javascript:, https://…). These call sites predate the recent AuthContext fix and were never guarded. - Add shared lib/safeRedirect.ts (same-origin relative paths only; rejects protocol-relative, absolute, and protocol-bearing values) - Wrap redirect_path at all 4 call sites in login/register Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Warning Review limit reached
More reviews will be available in 45 minutes and 4 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds a redirect-path sanitizer and routes post-auth navigation in the login and register pages through it instead of using raw redirect values. ChangesAuth redirect sanitization
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@frontend/lib/safeRedirect.ts`:
- Around line 17-21: The safe redirect guard in safeRedirect should also reject
backslashes before the existing prefix/protocol checks, since values like
\evil.com or \/evil.com can still resolve to an external origin in browsers.
Update the validation logic in the safeRedirect function to either fail fast
when the input contains backslashes or normalize them before evaluating the
leading-slash and protocol rules, keeping the existing fallback behavior intact.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ab3b542f-c0b6-4629-83ea-0bbd27e1370c
📒 Files selected for processing (3)
frontend/app/auth/login/page.tsxfrontend/app/auth/register/page.tsxfrontend/lib/safeRedirect.ts
…pass) Browsers normalise "\" to "/" (WHATWG URL), so "/\evil.com" resolved to "//evil.com" and escaped origin — slipping past the // denylist check. Reject any value containing a backslash after decode. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Why
login/page.tsxandregister/page.tsxpushed the API-suppliedredirect_pathdirectly to the router:An attacker-influenced
redirect_path(//evil.com,javascript:,https://…) would be followed → open redirect. These call sites are pre-existing (identical before the recentfeat/verification-kycchurn) and were surfaced during the git audit behind #13. They're separate from the AuthContext guard restored in #13.Change
frontend/lib/safeRedirect.ts—safeRedirectPath()accepts only same-origin relative paths; rejects protocol-relative (//), absolute, and protocol-bearing (javascript:,http:) values; decodes first to catch encoded payloads.redirect_pathat all 4 call sites in login/register.Verification
tsc --noEmit→ clean (0).Note
AuthContext.tsx(restored in #13) andlogin's localgetSafeRedirectUrl(for thereturnUrlquery param) have near-identical logic. Consolidating all three onto this shared util is a reasonable, low-risk follow-up — left out here to keep this PR focused on the security gap.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes