Skip to content

http2: report invalid for spaced header names#33161

Closed
rexagod wants to merge 5 commits into
nodejs:masterfrom
rexagod:i-29829-5
Closed

http2: report invalid for spaced header names#33161
rexagod wants to merge 5 commits into
nodejs:masterfrom
rexagod:i-29829-5

Conversation

@rexagod
Copy link
Copy Markdown
Member

@rexagod rexagod commented Apr 30, 2020

Refs: #29829

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the http2 Issues or PRs related to the http2 subsystem. label Apr 30, 2020
@BridgeAR
Copy link
Copy Markdown
Member

BridgeAR commented May 3, 2020

@nodejs/http @nodejs/http2 @nodejs/streams PTAL

Copy link
Copy Markdown
Member

@ronag ronag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread lib/internal/http2/compat.js Outdated
Copy link
Copy Markdown
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@addaleax
Copy link
Copy Markdown
Member

@rexagod Is this semver-major? It looks that way to me.

@addaleax addaleax added the semver-major PRs that contain breaking changes and should be released in the next major version. label May 19, 2020
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

@rexagod
Copy link
Copy Markdown
Member Author

rexagod commented May 20, 2020

@addaleax +1. Thank you for tagging this!

Comment thread test/parallel/test-http2-invalidheaderfield.js Outdated
Copy link
Copy Markdown
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@BridgeAR BridgeAR force-pushed the master branch 2 times, most recently from 8ae28ff to 2935f72 Compare May 31, 2020 12:18
Comment thread test/parallel/test-http2-invalidheaderfield.js Outdated
Comment thread lib/internal/http2/util.js Outdated
Comment thread lib/internal/http2/compat.js Outdated
Comment thread test/parallel/test-http2-invalidheaderfield.js Outdated
Comment thread test/parallel/test-http2-invalidheaderfield.js Outdated
Copy link
Copy Markdown
Member Author

@rexagod rexagod Jun 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be equivalent to 'test', hence a valid header. See below.

name = name.trim().toLowerCase();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I wonder, the http fails with ERR_INVALID_HTTP_TOKEN if you try to set the header name of ' test'.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each header field consists
of a name followed by a colon (":") and the field value. Field names
are case-insensitive. The field value MAY be preceded by any amount
of LWS, though a single SP is preferred.

@lundibundi The RFC2616 for HTTP/1 states that the field value may be preceded by any amount of LWS, but nothing similar is stated for the field names. Furthermore, this is not a problem in HTTP/2 owing to the binary protocol.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That part of the RFC if referring to the format of the HTTP message (i.e. actual text representation of the message), not the specific field name/value. Just down below in that section, we can see
field-name = token
And the token is
token = 1*<any CHAR except CTLs or separators>

Therefore there shouldn't be any leading whitespace in the user-provided value for header name which our http/1 implementation is enforcing correctly (by throwing ERR_INVALID_HTTP_TOKEN).

It's fine to do that in a follow-up PR, I just mentioned it so that we won't forget about it.

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

Merging #33161 into master will increase coverage by 0.44%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #33161      +/-   ##
==========================================
+ Coverage   96.26%   96.71%   +0.44%     
==========================================
  Files         197      203       +6     
  Lines       65980    67388    +1408     
==========================================
+ Hits        63518    65171    +1653     
+ Misses       2462     2217     -245     
Impacted Files Coverage Δ
lib/internal/idna.js 66.66% <0.00%> (-33.34%) ⬇️
lib/internal/net.js 75.00% <0.00%> (-25.00%) ⬇️
lib/internal/inspector_async_hook.js 86.84% <0.00%> (-13.16%) ⬇️
lib/internal/source_map/source_map.js 84.50% <0.00%> (-11.71%) ⬇️
lib/internal/fs/rimraf.js 67.90% <0.00%> (-11.49%) ⬇️
lib/internal/v8_prof_processor.js 92.85% <0.00%> (-4.77%) ⬇️
lib/inspector.js 94.30% <0.00%> (-4.39%) ⬇️
lib/internal/source_map/source_map_cache.js 80.21% <0.00%> (-3.77%) ⬇️
lib/internal/modules/cjs/loader.js 94.85% <0.00%> (-3.06%) ⬇️
lib/internal/fs/utils.js 94.97% <0.00%> (-1.99%) ⬇️
... and 113 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cd4052c...2ffb264. Read the comment docs.

Comment thread test/parallel/test-http2-invalidheaderfield.js Outdated
Copy link
Copy Markdown
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Copy Markdown
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still lgtm

@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

@mcollina
Copy link
Copy Markdown
Member

@rexagod there are still a few comments to fix, then we can land.

@rexagod
Copy link
Copy Markdown
Member Author

rexagod commented Jun 16, 2020

@mcollina I think all the comments have been resolved now. Please let me know if there's anything else left to fix here.

Copy link
Copy Markdown
Member

@lundibundi lundibundi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Making explicit that IMO the leading whitespace in header names can be handled in a follow-up PR since this PR already improves things in compat layer a bit and there is no need to handle everything in one PR.

@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

mcollina pushed a commit that referenced this pull request Jun 17, 2020