Repository navigation
Validate newline chars in HTTP/3 dynamic-table header values - #70202
Conversation
dotnet#68743 set checkForNewlineChars to true in two places: the HTTP/2 dynamic-table header path in Http2Connection.OnHeaderCore, and the protocol-agnostic HttpProtocol.OnTrailer. The HTTP/3 counterpart of the first change was not made, so Http3Stream.OnHeaderCore still passes false for the same switch case. This is consistency hardening rather than a fix for a reachable issue: QPackDecoder never invokes OnDynamicIndexedHeader, so the branch cannot be reached today. It becomes correct by construction for whoever implements the QPACK dynamic table (RFC 9204 section 3.2).
|
Thanks for your PR, @earbona23. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
A note on the red checks, so they do not count against this PR while it waits. Four checks are red. Two of them are the Those two are not caused by this change: that pipeline is red on This PR touches one file, Happy to rebase if a fresh run would help. |
| { | ||
| UpdateHeaderParsingState(value, GetPseudoHeaderField(name)); | ||
|
|
||
| OnHeader(name, value, checkForNewlineChars: false); |
There was a problem hiding this comment.
Dynamic tables aren't supported. Can we just delete all the code and replace it with:
// Dynamic tables aren't currently implemented for HTTP/3
// Let's make sure this code is tested if we add dynamic table support in the future
// Make sure checkForNewlineChars is correct when adding support for dynamic table
// Consider using Http2Connection's dynamic table implementation as a reference if we add support for dynamic table in the future.
throw new UnreachableException();
There was a problem hiding this comment.
Hi bro, sure ...
There was a problem hiding this comment.
Done in 2ca86b3. The HeaderType.Dynamic case now carries those four comments and throw new UnreachableException();, with no break after it since that would be unreachable.
No using change was needed: System.Diagnostics is already imported in Http3Stream.cs, so UnreachableException resolves. Microsoft.AspNetCore.Server.Kestrel.Core builds with 0 warnings and 0 errors.
Nothing tested that branch. QPackDecoder rejects the dynamic table instructions and never calls OnDynamicIndexedHeader; the HTTP/3 newline coverage in Http3StreamTests.RequestTrailers_ContainsNewlines goes through the trailers path, and OnDynamicIndexedHeader_NewlineCharactersInValue_ThrowsConnectionError is HTTP/2 only and calls Http2Connection directly.
Dynamic tables are not implemented for HTTP/3. QPackDecoder rejects the dynamic table instructions and never calls OnDynamicIndexedHeader, so the HeaderType.Dynamic case in Http3Stream.OnHeaderCore is unreachable. Replace the body of that case with UnreachableException and a note to get checkForNewlineChars right, add tests, and use Http2Connection's dynamic table implementation as a reference whenever support is added.
|
thks @BrennanConroy |
|
/ba-g unrelated |
|
Thanks @earbona23 |
|
✅ No documentation PR was created. Confidence that documentation is needed: 3% No docs needed: internal consistency fix with no observable behavior change. Confident, not an insufficient-evidence case. Documentation surfaces considered
|
Summary
Http3Stream.OnHeaderCorepassescheckForNewlineChars: falsefor aHeaderType.Dynamicheader resolved by name, while the identical switch case inHttp2Connection.OnHeaderCorepassestrue. This PR makes the HTTP/3 side match.#68743 (which closed #68371) made exactly two source changes:
Http2Connection.cs,case HeaderType.DynamiccheckForNewlineChars: false->trueHttpProtocol.cs,OnTrailercheckForNewlineChars: false->trueHttpProtocol.OnTraileris protocol-agnostic, which is why the HTTP/3 trailer tests added in that PR pass without any HTTP/3 source change. The HTTP/3 counterpart of the first change was not made.Is this reachable today?
No, and this PR does not claim otherwise.
HPackDecoderis the only caller ofOnDynamicIndexedHeaderin the product (src/Shared/runtime/Http2/Hpack/HPackDecoder.cs), and it is HTTP/2 only.QPackDecoderinvokes just three callbacks, all of which land on paths that already validate:OnStaticIndexedHeader(index, value)->TryQPackAppend(index, value, checkForNewlineChars: !indexOnly)OnHeader(name, value)->ValidateHeaderContentpluscheckForNewlineChars: trueOnStaticIndexedHeader(index)-> static-table valueKestrel does not implement the QPACK dynamic table, so this branch cannot be reached from the network.
Why change it anyway
The two switch statements are otherwise identical, and within the HTTP/3 switch the neighbouring
HeaderType.NameAndValuecase validates while this one does not, with no comment explaining the difference. Setting it totruenow means the line is correct by construction if the QPACK dynamic table (RFC 9204 section 3.2) is ever implemented, rather than shipping on day one with the HTTP/2 bug that #68743 fixed.Checklist
OnDynamicIndexedHeader_NewlineCharactersInValue_ThrowsConnectionError, which calls the handler directly. The server-sideHttp3Streamis not exposed by the in-memory HTTP/3 test harness, which hands tests the client-sideHttp3RequestStream. Happy to add one behind a test hook if you would prefer that.