-
-
Notifications
You must be signed in to change notification settings - Fork 34.6k
http: align header value validation with Fetch spec #61597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
http: align header value validation with Fetch spec #61597
Conversation
Per the Fetch spec, header values should only reject NUL (0x00), LF (0x0a), CR (0x0d), and characters above 0xff. Previously, Node.js rejected all CTL characters which was more restrictive than the spec and prevented valid use cases. This change relaxes the validation to match browser behavior while still protecting against response splitting attacks. Fixes: nodejs#61582
|
Review requested:
|
mcollina
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
|
cc @nodejs/tsc this require a few more sets of eyes |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #61597 +/- ##
==========================================
- Coverage 89.77% 89.75% -0.02%
==========================================
Files 673 673
Lines 203840 203949 +109
Branches 39180 39194 +14
==========================================
+ Hits 182998 183064 +66
- Misses 13156 13194 +38
- Partials 7686 7691 +5
🚀 New features to boost your workflow:
|
RafaelGSS
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though this seems like a fix, I believe this could be considered a semver-major PR.
For node:http, this is not a fix but an elective behavioural change:
So, not required, but compliant optional. Footnotes |
This PR aligns Node.js HTTP header value validation with the Fetch spec, which only forbids:
0x00(NUL)0x0a(LF)0x0d(CR)0xff(non-byte sequences)Changes
The
headerCharRegexinlib/_http_common.jsis updated from:to:
Security Consideration
@Renegade334 raised a valid concern about CVE-2016-2216 (response splitting). This change is safe because:
Response splitting requires CRLF injection - The attack relies on injecting
\r\n(0x0d0x0a) to create fake headers. This fix still rejects both CR and LF.Other CTL characters cannot cause response splitting - Characters like
0x01-0x08,0x0b-0x0c,0x0e-0x1f, and0x7fhave no special meaning in HTTP protocol parsing.Browser alignment - Browsers already allow these characters per Fetch spec (verified via WPT test
fetch/api/headers/header-values.any.js).Tests
Updated
test/parallel/test-http-invalidheaderfield2.jsto reflect the new valid/invalid character sets.Fixes: #61582
Refs: https://fetch.spec.whatwg.org/#header-value