fix(backend): Do not throw URIError when a cookie has a malformed percent-escape - #9345
fix(backend): Do not throw URIError when a cookie has a malformed percent-escape#9345kev-flex wants to merge 1 commit into
Conversation
|
@kev-flex is attempting to deploy a commit to the Clerk Production Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: e0ac1d2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 10 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 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🔗 Linked repositories identifiedCodeRabbit considers these linked repositories for cross-repo context during reviews:
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthrough
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
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 |
…cent-escape ClerkRequest decodes percent-escapes across the whole Cookie header rather than per value, so an invalid sequence in any cookie reached decodeURIComponent and threw URIError: URI malformed. The decode runs from the constructor, so the error escaped createClerkRequest and failed the request before any auth logic ran. Escape runs that cannot be decoded are now left as their raw text.
f530c18 to
e0ac1d2
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
Description
Fixes #9333.
ClerkRequestdecodes percent-escapes across the wholeCookieheader rather than per value, so an invalid sequence in any cookie — including ones Clerk neither set nor reads, such as those written by analytics or third-party scripts — reacheddecodeURIComponentand threwURIError: URI malformed. The decode runs from the constructor, so the error escapedcreateClerkRequestand failed the request before any auth logic ran. Because the offending value stays in the browser until it expires, every subsequent request from that client failed too; on@clerk/nextjsthis surfaces as a 500 fromclerkMiddleware()that the application has no way to catch.Escape runs that cannot be decoded are now left as their raw text, and the rest of the header parses as before.
Whole-header decoding is deliberately preserved, so the existing behaviour where an escaped
;splits one value into separate cookies (foo=%20bar%3B%20baz%3Dqux→foo=bar,baz=qux) is unchanged and its test still passes.Covered by tests for the three shapes reported in the issue: truncated sequence (
%E2%9), lone continuation byte (%98), and overlong encoding (%C0%80). Each throws onmainand passes here.The lowercase-hex asymmetry also noted in #9333 (
%c3%a9is left raw while%C3%A9decodes) is intentionally left alone. Fixing it would change parsed cookie values for existing users rather than just stop a crash, so it seems better suited to its own change.Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change