Skip to content

fix(runtime): match route rules on canonical path#4396

Draft
pi0 wants to merge 6 commits into
mainfrom
fix/route-rules-encoded-slash-auth-bypass
Draft

fix(runtime): match route rules on canonical path#4396
pi0 wants to merge 6 commits into
mainfrom
fix/route-rules-encoded-slash-auth-bypass

Conversation

@pi0

@pi0 pi0 commented Jun 30, 2026

Copy link
Copy Markdown
Member

No description provided.

A request like `/app/admin%2fpanel` keeps `%2f` opaque in `event.url.pathname`
(h3 `decodeURI`s the path but leaves `/`/`\` reserved), so route-rule matching
never saw a literal `admin` segment: a narrow `basicAuth` rule on
`/app/admin/**` was skipped while a broader proxy rule on `/app/**` still
forwarded the request. Downstreams that decode `%2f` back to `/` (Apache, PHP,
most CDNs) then served the protected resource with no credentials.

Match route rules on a canonical path that additionally decodes `%2f`/`%5c`
and resolves `.`/`..` segments, so an auth rule matches whenever the served
path would. This mirrors nginx ($uri decoded for location matching,
$request_uri raw for proxy_pass) — proxy/redirect targets keep forwarding the
raw path.

Canonicalization uses string ops (mirroring h3's internal resolveDotSegments)
rather than `new URL`, which would re-encode characters h3 already decoded
(spaces, non-ASCII) and desync matching from `event.url.pathname`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 30, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
nitro.build Ready Ready Preview, Comment Jun 30, 2026 6:28pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1a19c565-5982-4f53-9afb-9181162317e9

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/route-rules-encoded-slash-auth-bypass

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.

@pkg-pr-new

pkg-pr-new Bot commented Jun 30, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/nitro@4396

commit: d242227

@pi0 pi0 changed the title fix(runtime): match route rules on canonical path to prevent auth bypass fix(runtime): match route rules on canonical path Jun 30, 2026
`event.url.pathname` is not `decodeURI`-d; srvx FastURL keeps percent-encodings
opaque (only literal `.`/`..` and `\` are WHATWG-resolved). Fix the inaccurate
comments and the unit test that fed already-decoded inputs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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