Skip to content

Validate newline chars in HTTP/3 dynamic-table header values - #70202

Merged
BrennanConroy merged 2 commits into
dotnet:mainfrom
earbona23:h3-dynamic-header-newline-chars
Nov 2, 2026
Merged

BrennanConroy merged 2 commits into
dotnet:mainfrom
earbona23:h3-dynamic-header-newline-chars

Conversation

@earbona23

Copy link
Copy Markdown
Contributor

Summary

Http3Stream.OnHeaderCore passes checkForNewlineChars: false for a HeaderType.Dynamic header resolved by name, while the identical switch case in Http2Connection.OnHeaderCore passes true. This PR makes the HTTP/3 side match.

#68743 (which closed #68371) made exactly two source changes:

file change
Http2Connection.cs, case HeaderType.Dynamic checkForNewlineChars: false -> true
HttpProtocol.cs, OnTrailer checkForNewlineChars: false -> true

HttpProtocol.OnTrailer is 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.

HPackDecoder is the only caller of OnDynamicIndexedHeader in the product (src/Shared/runtime/Http2/Hpack/HPackDecoder.cs), and it is HTTP/2 only. QPackDecoder invokes just three callbacks, all of which land on paths that already validate:

  • OnStaticIndexedHeader(index, value) -> TryQPackAppend(index, value, checkForNewlineChars: !indexOnly)
  • OnHeader(name, value) -> ValidateHeaderContent plus checkForNewlineChars: true
  • OnStaticIndexedHeader(index) -> static-table value

Kestrel 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.NameAndValue case validates while this one does not, with no comment explaining the difference. Setting it to true now 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

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable. No test is added: the branch cannot be exercised through the decoder, and the HTTP/2 analogue is covered by OnDynamicIndexedHeader_NewlineCharactersInValue_ThrowsConnectionError, which calls the handler directly. The server-side Http3Stream is not exposed by the in-memory HTTP/3 test harness, which hands tests the client-side Http3RequestStream. Happy to add one behind a test hook if you would prefer that.
  • You've included inline docs for your change, where applicable. Not applicable.
  • There's an open issue for the PR that you are making. The related issue is Harden HTTP/2 CR/LF in trailer header values #68371, closed by Fix: hardening http2 to refuse newline chars on trailers and dynamic HPACK table #68743. I did not open a new one because nothing is reachable here, but happy to if you prefer.

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).
@github-actions github-actions Bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Oct 31, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Oct 31, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @earbona23. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@earbona23

Copy link
Copy Markdown
Contributor Author

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 Build Analysis and Build Insights summaries, which reflect the other two rather than finding anything of their own. The two real ones are aspnetcore-components-e2e and its Blazor E2E tests on Linux (Mono client and WebAssembly) job.

Those two are not caused by this change: that pipeline is red on main as well. Of the last twelve runs of definition 87 on refs/heads/main, nine failed and three partially succeeded, and none was fully green. Checked against the public build API on 1 November; the most recent run is 20261030.29.

This PR touches one file, QPackDecoder-side header validation for HTTP/3, and adds no component or WebAssembly code, so there is no path from it to a Blazor end-to-end test.

Happy to rebase if a fresh run would help.

{
UpdateHeaderParsingState(value, GetPseudoHeaderField(name));

OnHeader(name, value, checkForNewlineChars: false);

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.

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();

@earbona23 earbona23 Nov 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi bro, sure ...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.
@earbona23

Copy link
Copy Markdown
Contributor Author

thks @BrennanConroy

@BrennanConroy

Copy link
Copy Markdown
Member

/ba-g unrelated

@BrennanConroy
BrennanConroy merged commit 480401c into dotnet:main Nov 2, 2026
27 of 29 checks passed
@BrennanConroy

Copy link
Copy Markdown
Member

Thanks @earbona23

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

✅ 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

  • Conceptual article: Not required — Single internal line in Http3Stream.cs; the branch is unreachable because Kestrel doesn't implement the QPACK dynamic table. No user-visible behavior.
  • Migration guidance: Not required — No action for users upgrading.
  • Breaking change: Not required — No compatibility impact; no API, default, or reachable behavior changes.

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 2ca86b3e Deployed Nov 2, 2026 by BrennanConroy via conclusion #155
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Harden HTTP/2 CR/LF in trailer header values

2 participants