Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6583016

Browse filesBrowse files
joyeecheunggibfahn
authored andcommitted
http2: improve errors thrown in header validation
PR-URL: #16718 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 8cf8a32 commit 6583016
Copy full SHA for 6583016

File tree

Expand file treeCollapse file tree

5 files changed

+18
-12
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+18
-12
lines changed
Open diff view settings
Collapse file

‎doc/api/errors.md‎

Copy file name to clipboardExpand all lines: doc/api/errors.md
+1-1Lines changed: 1 addition & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ requests and responses.
711711
<a id="ERR_HTTP2_INVALID_HEADER_VALUE"></a>
712712
### ERR_HTTP2_INVALID_HEADER_VALUE
713713

714-
Used to indicate that an invalid HTTP/2 header value has been specified.
714+
Used to indicate that an invalid HTTP2 header value has been specified.
715715

716716
<a id="ERR_HTTP2_INVALID_INFO_STATUS"></a>
717717
### ERR_HTTP2_INVALID_INFO_STATUS
Collapse file

‎lib/internal/errors.js‎

Copy file name to clipboardExpand all lines: lib/internal/errors.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ E('ERR_HTTP2_INFO_STATUS_NOT_ALLOWED',
185185
'Informational status codes cannot be used');
186186
E('ERR_HTTP2_INVALID_CONNECTION_HEADERS',
187187
'HTTP/1 Connection specific headers are forbidden: "%s"');
188-
E('ERR_HTTP2_INVALID_HEADER_VALUE', 'Value must not be undefined or null');
188+
E('ERR_HTTP2_INVALID_HEADER_VALUE', 'Invalid value "%s" for header "%s"');
189189
E('ERR_HTTP2_INVALID_INFO_STATUS',
190190
(code) => `Invalid informational status code: ${code}`);
191191
E('ERR_HTTP2_INVALID_PACKED_SETTINGS_LENGTH',
Collapse file

‎lib/internal/http2/compat.js‎

Copy file name to clipboardExpand all lines: lib/internal/http2/compat.js
+12-6Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,18 @@ let statusMessageWarned = false;
4040
// close as possible to the current require('http') API
4141

4242
function assertValidHeader(name, value) {
43-
if (name === '' || typeof name !== 'string')
44-
throw new errors.TypeError('ERR_INVALID_HTTP_TOKEN', 'Header name', name);
45-
if (isPseudoHeader(name))
46-
throw new errors.Error('ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED');
47-
if (value === undefined || value === null)
48-
throw new errors.TypeError('ERR_HTTP2_INVALID_HEADER_VALUE');
43+
let err;
44+
if (name === '' || typeof name !== 'string') {
45+
err = new errors.TypeError('ERR_INVALID_HTTP_TOKEN', 'Header name', name);
46+
} else if (isPseudoHeader(name)) {
47+
err = new errors.Error('ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED');
48+
} else if (value === undefined || value === null) {
49+
err = new errors.TypeError('ERR_HTTP2_INVALID_HEADER_VALUE', value, name);
50+
}
51+
if (err !== undefined) {
52+
Error.captureStackTrace(err, assertValidHeader);
53+
throw err;
54+
}
4955
}
5056

5157
function isPseudoHeader(name) {
Collapse file

‎test/parallel/test-http2-compat-serverresponse-headers.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http2-compat-serverresponse-headers.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ server.listen(0, common.mustCall(function() {
8585
}, common.expectsError({
8686
code: 'ERR_HTTP2_INVALID_HEADER_VALUE',
8787
type: TypeError,
88-
message: 'Value must not be undefined or null'
88+
message: 'Invalid value "null" for header "foo-bar"'
8989
}));
9090
assert.throws(function() {
9191
response.setHeader(real, undefined);
9292
}, common.expectsError({
9393
code: 'ERR_HTTP2_INVALID_HEADER_VALUE',
9494
type: TypeError,
95-
message: 'Value must not be undefined or null'
95+
message: 'Invalid value "undefined" for header "foo-bar"'
9696
}));
9797
common.expectsError(
9898
() => response.setHeader(), // header name undefined
Collapse file

‎test/parallel/test-http2-compat-serverresponse-trailers.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http2-compat-serverresponse-trailers.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ server.listen(0, common.mustCall(() => {
2828
{
2929
code: 'ERR_HTTP2_INVALID_HEADER_VALUE',
3030
type: TypeError,
31-
message: 'Value must not be undefined or null'
31+
message: 'Invalid value "undefined" for header "test"'
3232
}
3333
);
3434
common.expectsError(
3535
() => response.setTrailer('test', null),
3636
{
3737
code: 'ERR_HTTP2_INVALID_HEADER_VALUE',
3838
type: TypeError,
39-
message: 'Value must not be undefined or null'
39+
message: 'Invalid value "null" for header "test"'
4040
}
4141
);
4242
common.expectsError(

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.