fix: reject non-ascii octets in validateCookiePath#5452
Open
spokodev wants to merge 1 commit into
Open
Conversation
RFC 6265 section 4.1.1 defines path-value as <any CHAR except CTLs or ";">, where CHAR is a US-ASCII character (0x00-0x7F). validateCookiePath rejected control characters and ";" but accepted octets above 0x7E, unlike its sibling validators validateCookieName and validateCookieValue, which both reject code > 0x7E. Add the upper bound so non-ascii and C1 control octets are rejected too.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5452 +/- ##
=======================================
Coverage 93.46% 93.47%
=======================================
Files 110 110
Lines 37106 37106
=======================================
+ Hits 34682 34683 +1
+ Misses 2424 2423 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
validateCookiePathinlib/web/cookies/util.jsaccepts octets above0x7E(non-ascii and C1 controls), which RFC 6265 prohibits for a cookie path.Why
RFC 6265 §4.1.1 defines:
where
CHARis a US-ASCII character (0x00-0x7F). The current check rejectscode < 0x20(CTLs),code === 0x7F(DEL) andcode === 0x3B(;), but has no upper bound, so any code point from0x80to0xFFpasses:This is inconsistent with the two sibling validators in the same file, which both reject
code > 0x7E:validateCookieName—code > 0x7EpresentvalidateCookieValue—code > 0x7EpresentvalidateCookiePath—code > 0x7EmissingIt is reachable from the public
setCookie(headers, { path })API. This is a conformance defect, not a security issue: CR, LF and other control octets are already rejected by thecode < 0x20clause, so no header injection is possible.Fix
Replace the redundant
code === 0x7Fclause with the upper boundcode > 0x7E, matching the sibling validators. DEL (0x7F) stays rejected because0x7F > 0x7E.if ( code < 0x20 || // exclude CTLs (0-31) - code === 0x7F || // DEL + code > 0x7E || // exclude non-ascii and DEL code === 0x3B // ; ) {Tests
Added a case to
test/cookie/validate-cookie-path.jsasserting that a non-ascii path and the C1 control range throw. It fails onmain(Missing expected exception) and passes with the fix. The existing DEL and printable-character cases still pass.