http: align header value validation with Fetch spec #61597
+28
−13
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.
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