Repository navigation
http2: reject non-latin1 client request values #63571
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
Open
mcollina
wants to merge
3
commits into
nodejs:main
Choose a base branch
from
mcollina:fix/http2-reject-nonlatin1-client-request-values-pr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| 'use strict'; | ||
| const common = require('../common'); | ||
| if (!common.hasCrypto) { common.skip('missing crypto'); } | ||
| const assert = require('assert'); | ||
| const http2 = require('http2'); | ||
|
|
||
| // Integration tests for the http2.connect() `httpValidation` option. | ||
| // See also test-http2-util-headers-list.js for the per-value validation logic. | ||
|
|
||
| const server = http2.createServer(); | ||
| // Consume any stream that is actually created. Control characters and | ||
| // duplicate pseudo-headers may be rejected by nghttp2 asynchronously, so | ||
| // swallow any stream errors rather than letting them become uncaught. | ||
| server.on('stream', (stream) => { | ||
| stream.on('error', () => {}); | ||
| }); | ||
|
|
||
| server.listen(0, common.mustCall(() => { | ||
| const origin = `http://localhost:${server.address().port}`; | ||
|
|
||
| function swallow(stream) { | ||
| stream.on('error', () => {}); | ||
| stream.destroy(); | ||
| return stream; | ||
| } | ||
|
|
||
| // -- strict (default) -- | ||
| { | ||
| const session = http2.connect(origin); | ||
| session.on('error', () => {}); | ||
| // Non-latin1 characters are rejected by default. | ||
| assert.throws(() => session.request({ 'x-bad-char': 'oʊmɪɡə' }), { | ||
| code: 'ERR_HTTP2_INVALID_HEADER_VALUE', | ||
| }); | ||
| // Control characters are rejected by default per the HTTP RFCs. | ||
| assert.throws(() => session.request({ 'x-control': 'value\x01here' }), { | ||
| code: 'ERR_HTTP2_INVALID_HEADER_VALUE', | ||
| }); | ||
| // strictSingleValueFields is enabled by default. | ||
| assert.throws(() => session.request([ | ||
| ':method', 'GET', ':method', 'POST', | ||
| ]), { | ||
| code: 'ERR_HTTP2_HEADER_SINGLE_VALUE', | ||
| }); | ||
| // The :path pseudo-header must not contain unescaped characters. | ||
| assert.throws(() => session.request({ ':path': 'bad\u0100path' }), { | ||
| code: 'ERR_UNESCAPED_CHARACTERS', | ||
| }); | ||
| session.close(); | ||
| } | ||
|
|
||
| // -- relaxed -- | ||
| { | ||
| const session = http2.connect(origin, { httpValidation: 'relaxed' }); | ||
| session.on('error', () => {}); | ||
| // Control characters permitted by the Fetch specification are allowed. | ||
| swallow(session.request({ 'x-control': 'value\x01here' })); | ||
| // relaxed/insecure mode subsumes and disables strictSingleValueFields. | ||
| swallow(session.request([ | ||
| ':method', 'GET', ':method', 'POST', | ||
| ])); | ||
| // Non-latin1 characters are still rejected in relaxed mode. | ||
| assert.throws(() => session.request({ 'x-bad-char': 'oʊmɪɡə' }), { | ||
| code: 'ERR_HTTP2_INVALID_HEADER_VALUE', | ||
| }); | ||
| // NUL is always rejected. | ||
| assert.throws(() => session.request({ 'x-nul': 'value\x00here' }), { | ||
| code: 'ERR_HTTP2_INVALID_HEADER_VALUE', | ||
| }); | ||
| // The :path pseudo-header check is always enforced. | ||
| assert.throws(() => session.request({ ':path': 'bad\u0100path' }), { | ||
| code: 'ERR_UNESCAPED_CHARACTERS', | ||
| }); | ||
| session.close(); | ||
| } | ||
|
|
||
| // -- insecure -- | ||
| { | ||
| const session = http2.connect(origin, { httpValidation: 'insecure' }); | ||
| session.on('error', () => {}); | ||
| // All header value validation is skipped, including newlines. | ||
| swallow(session.request({ 'x-newline': 'value\nhere' })); | ||
| // strictSingleValueFields is disabled in insecure mode too. | ||
| swallow(session.request([ | ||
| ':method', 'GET', ':method', 'POST', | ||
| ])); | ||
| // The :path pseudo-header check is still enforced. | ||
| assert.throws(() => session.request({ ':path': 'bad\u0100path' }), { | ||
| code: 'ERR_UNESCAPED_CHARACTERS', | ||
| }); | ||
| session.close(); | ||
| } | ||
|
|
||
| // -- invalid option value -- | ||
| { | ||
| assert.throws(() => http2.connect(origin, { httpValidation: 'bogus' }), { | ||
| code: 'ERR_INVALID_ARG_VALUE', | ||
| }); | ||
| } | ||
|
|
||
| server.close(); | ||
| })); |
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Insecure mode should still reject
NUL,CR, andLFin outgoing values to match HTTP/1. This comes from the design in #61597 (see the "Security Consideration" section).