Skip to content

fix(web): a post-login target that normalizes to //host goes home - #1312

Open
JOY (JOY) wants to merge 1 commit into
devfrom
fix/auth-redirect-dot-segments
Open

JOY (JOY) wants to merge 1 commit into
devfrom
fix/auth-redirect-dot-segments

Conversation

@JOY

@JOY JOY (JOY) commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1305

From the apps/web security review. Severity: medium (phishing aid, no data exposure).

What

  • sanitizeAuthRedirectTarget (components/auth/RateAuthPortal.tsx): after parsing, a target whose pathname starts with // or contains a backslash goes to /. Dot segments could normalize a same-origin-looking value into a protocol-relative path, which the client router reads as another host.
  • proxy.ts: the locale-prefix 308 collapses leading slashes, so it never emits a Location with two leading slashes (defence in depth; the Node server normalizes such paths first).

Tests (core-rate-architecture.test.ts)

The normalizing forms go to /; a normal relative path with .. still resolves on the site; /en//... 308s to a one-slash path.

Review gate

Codex adversarial, 1 round: no bypass found (about 318,000 generated inputs: encodings, control characters, Unicode, dot segments, query and hash, javascript:, long strings), and the locale Location outputs are as expected.

Checks

Web pnpm test, tsc --noEmit, eslint, prettier: green locally.

🤖 Generated with Claude Code


📌 TL;DR

This PR hardens the application against Open Redirect vulnerabilities by sanitizing URL paths that normalize to protocol-relative targets (e.g., //evil.com) in both the auth redirect handler and the locale proxy middleware.

🎯 Type of Change

  • 🚀 New feature
  • 🐛 Bugfix
  • 🧹 Refactor
  • ⚡ Performance
  • 📚 Documentation
  • ⚙️ CI / Configuration

🔍 Changes Walkthrough

File Summary of Changes
apps/web/src/components/auth/RateAuthPortal.tsx Enhanced sanitizeAuthRedirectTarget to reject paths starting with // or containing backslashes, preventing dot-segment normalization attacks (e.g., /.//host) from bypassing origin checks.
apps/web/src/proxy.ts Updated localeProxy to strip leading slashes from the path segment after the locale prefix, ensuring that inputs like /en//host do not result in a protocol-relative redirect.
apps/web/src/server/rate/__tests__/core-rate-architecture.test.ts Added regression tests verifying that the middleware and sanitizer correctly handle double-slash and dot-segment edge cases to prevent open redirects.

📊 Architectural Flow

flowchart TD
    A[Incoming Request] --> B{Is Auth Redirect?}
    B -->|Yes| C[sanitizeAuthRedirectTarget]
    C --> D{Origin Valid?}
    D -->|No| E[Return /]
    D -->|Yes| F{Path starts with // or contains \\?}
    F -->|Yes| E
    F -->|No| G[Return Sanitized Path]
    
    B -->|No| H{Has Locale Prefix?}
    H -->|Yes| I[Extract Path Segment]
    I --> J[Strip Leading Slashes]
    J --> K[Construct Safe Redirect URL]
    H -->|No| L[Pass Through]
Loading

The callbackUrl sanitizer checked the raw value for a leading '//', but
dot segments normalize into a protocol-relative path after parsing, which
the router reads as another host. The parsed pathname is now checked
too. The locale-prefix 308 also collapses leading slashes, so it never
emits a two-slash Location.

Closes #1305

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.

Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.

@vercel

vercel Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
rate Ready Ready Preview Oct 28, 2026 7:26pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Oct 28, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 7 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e6bc2916-124a-4d83-a9ae-a50b138e8d24
Commits

Reviewing files that changed from the base of the PR and between 4eca23d and 1c117bf.

Files selected for processing: 3
  • apps/web/src/components/auth/RateAuthPortal.tsx
  • apps/web/src/proxy.ts
  • apps/web/src/server/rate/__tests__/core-rate-architecture.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

dos[bot]
dos Bot approved these changes Oct 28, 2026

@dos dos Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱️ Code Review completed (3 eligible files · 3,450 chars · 2 model call(s) · 1 PR unit(s))

Whole diff with bounded context at base 3388764 / head 1c117bf.

✅ CLEAN_PASS: Complete diff reviewed

Context investigation was bounded to the explicitly requested snapshot paths.

This branch was successfully deployed

1 active deployment
Preview — 1c117bfa Deployed Oct 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:frontend Frontend / Next.js / UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(web): post-login redirect target can leave the site after path normalization

1 participant