fix(shared,nextjs,astro,nuxt): normalize URL paths in createPathMatcher#8310
Conversation
…tcher createPathMatcher now decodes percent-encoded characters before matching, preventing route protection bypass via encoded URLs (e.g. /api/%61dmin bypassing /api/admin). Malformed encodings return HTTP 400.
…ding expectation The nuxt middleware catches MalformedURLError and returns 400, not 404. Also run nuxt prepare after pkglab install since --ignore-scripts skips postinstall.
Collapse consecutive slashes (e.g. //api/admin -> /api/admin) before regex matching to prevent potential auth bypass via double-slash URLs.
…lformedURLError on client Switch from decodeURIComponent to decodeURI so reserved delimiters (%2F, %3F, %23) are preserved. This aligns matcher behavior with framework router semantics — %2F stays as a literal segment character rather than being decoded into a path separator. Catch MalformedURLError in Nuxt client createRouteMatcher to prevent uncaught exceptions during client-side navigation with malformed paths.
Move percent-encoded URL, dot segment, and double slash bypass tests from dynamic-keys.test.ts into integration/tests/nextjs/middleware.test.ts to match the Astro and Nuxt test structure.
Catching MalformedURLError and returning false on the client side silently treats malformed URLs as unprotected routes, which is the wrong failure mode for a security check. Let the error propagate instead (fail closed).
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
🦋 Changeset detectedLatest commit: 1d45fbf The changes in this PR will be included in the next version bump. This PR includes changesets to release 22 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/elements
@clerk/clerk-expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/clerk-react
@clerk/react-router
@clerk/remix
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/themes
@clerk/types
@clerk/upgrade
@clerk/vue
commit: |
The astro-node template on release/core-2 uses 'astro check && astro build' as the build script. The dynamically added middleware file fails type checking with the older @clerk/astro@2.x types. Override with 'astro build' only, which is also what the main branch template uses.
Summary
normalizePathto@clerk/sharedwhich normalizes URL paths before route matching increatePathMatcher, preventing route protection bypass via malformed or non-canonical pathsMalformedURLErrorwith a cross-bundleisMalformedURLErrorcheck; each framework middleware (Next.js, Astro, Nuxt) catches this and returns HTTP 400normalizePathandcreatePathMatcher, plus integration tests for all three frameworks covering path normalization edge casesTest plan
packages/sharedpathMatcher unit tests passpackages/nextjsclerkMiddleware unit tests pass