http2: validate non-link headers in writeEarlyHints#62017
Conversation
|
Review requested:
|
Sorry, something went wrong.
There was a problem hiding this comment.
Pull request overview
This PR hardens writeEarlyHints() by validating non-link headers (names + values) before emitting 103 Early Hints, aligning behavior with other header-writing code paths across the HTTP stack.
Changes:
- Add
validateHeaderName()/validateHeaderValue()checks for non-linkearly hints in the HTTP/1.1 server response path. - Add
assertValidHeader()checks for non-linkearly hints in the HTTP/2 compat server response path. - Add/extend parallel tests covering invalid early-hints header name/value handling for HTTP/1.1 and HTTP/2.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
lib/_http_server.js |
Validates non-link early-hints header names/values before writing the 103 response. |
lib/internal/http2/compat.js |
Validates non-link early-hints headers in the HTTP/2 compat layer before sending informational headers. |
test/parallel/test-http-early-hints-invalid-argument.js |
Adds assertions for invalid early-hints header names and CRLF in values (HTTP/1.1). |
test/parallel/test-http2-compat-write-early-hints-invalid-header.js |
Adds assertions for invalid early-hints header names and invalid values (HTTP/2 compat). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
bf5cf85 to
69e6ce4
Compare
February 27, 2026 12:36
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #62017 +/- ##
==========================================
+ Coverage 90.03% 90.05% +0.01%
==========================================
Files 713 714 +1
Lines 224950 225246 +296
Branches 42530 42576 +46
==========================================
+ Hits 202541 202840 +299
+ Misses 14184 14180 -4
- Partials 8225 8226 +1
🚀 New features to boost your workflow:
|
Sorry, something went wrong.
|
semver-major? |
Sorry, something went wrong.
pimterry
left a comment
There was a problem hiding this comment.
There's conflicts here due to the preceding PR (#61897) that covered some of this already. I imagine you're aware of that since you approved it 😆
The key difference is that this handles the HTTP/2 side - once the conflicts are fixed, can we update the commit message to make it clear this change just fixes the HTTP/2 compat API?
Sorry, something went wrong.
|
I review endless stream of PRs 😰 |
Sorry, something went wrong.
69e6ce4 to
0ed213a
Compare
May 13, 2026 13:17
Validate header names and values for non-link hints passed to writeEarlyHints() in the HTTP/2 compat layer using assertValidHeader() and checkIsHttpToken(), consistent with the HTTP/1.1 validation added in nodejs#61897. Previously, hints were forwarded into the headers object without any validation, allowing invalid characters in header names/values to surface as opaque errors deeper in the HTTP/2 stack. Signed-off-by: Matteo Collina <hello@matteocollina.com>
0ed213a to
ee38509
Compare
May 13, 2026 13:20
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
274d799
into
nodejs:main
May 15, 2026
Validate header names and values for non-link hints passed to writeEarlyHints() in the HTTP/2 compat layer using assertValidHeader() and checkIsHttpToken(), consistent with the HTTP/1.1 validation added in #61897. Previously, hints were forwarded into the headers object without any validation, allowing invalid characters in header names/values to surface as opaque errors deeper in the HTTP/2 stack. Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: #62017 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Validate header names and values for non-link hints passed to writeEarlyHints() in the HTTP/2 compat layer using assertValidHeader() and checkIsHttpToken(), consistent with the HTTP/1.1 validation added in #61897. Previously, hints were forwarded into the headers object without any validation, allowing invalid characters in header names/values to surface as opaque errors deeper in the HTTP/2 stack. Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: #62017 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Validate header names and values for non-link hints passed to writeEarlyHints() in the HTTP/2 compat layer using assertValidHeader() and checkIsHttpToken(), consistent with the HTTP/1.1 validation added in nodejs#61897. Previously, hints were forwarded into the headers object without any validation, allowing invalid characters in header names/values to surface as opaque errors deeper in the HTTP/2 stack. Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: nodejs#62017 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Validate header names and values for non-link hints passed to writeEarlyHints() in the HTTP/2 compat layer using assertValidHeader() and checkIsHttpToken(), consistent with the HTTP/1.1 validation added in #61897. Previously, hints were forwarded into the headers object without any validation, allowing invalid characters in header names/values to surface as opaque errors deeper in the HTTP/2 stack. Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: #62017 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Summary
The HTTP/1.1 portion of the original PR landed separately in #61897. This PR now contains only the HTTP/2 compat layer counterpart.
Http2ServerResponse.prototype.writeEarlyHints()usingassertValidHeader()andcheckIsHttpToken()Test plan
test/parallel/test-http2-compat-write-early-hints-invalid-header.js— verifiesERR_INVALID_HTTP_TOKENfor bad header names andERR_HTTP2_INVALID_HEADER_VALUEfor bad values