Skip to content

fix http2/3 path header ASCII symbols validation - #67109

Merged
wtgodbe merged 1 commit into
mainfrom
wtgodbe/ascii
Jun 10, 2026
Merged

wtgodbe merged 1 commit into
mainfrom
wtgodbe/ascii

Conversation

@wtgodbe

@wtgodbe wtgodbe commented Jun 10, 2026

Copy link
Copy Markdown
Member

No description provided.

…validation

Enforce a check for non-ASCII characters in the :path header for HTTP2/HTTP3. HTTP1 is not impacted

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix to enforce ASCII validation for HTTP/2 and HTTP/3 `:path` header processing.

#### PR Summary
Adds runtime validation for non-ASCII/control characters in the `:path` segment for HTTP/2 and HTTP/3 streams, aborting the stream with a protocol error instead of relying on `Debug.Assert`.
- `src/Servers/Kestrel/Core/src/Internal/Http2/Http2Stream.cs`: Replace `Debug.Assert` with explicit ASCII-range check; reset/abort the stream with `PROTOCOL_ERROR` on invalid characters.
- `src/Servers/Kestrel/Core/src/Internal/Http3/Http3Stream.cs`: Replace `Debug.Assert` with explicit ASCII-range check; abort the stream with `ProtocolError` on invalid characters.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
@wtgodbe
wtgodbe requested a review from DeagleGross June 10, 2026 00:19
@wtgodbe
wtgodbe requested a review from halter73 as a code owner June 10, 2026 00:19
Copilot AI review requested due to automatic review settings June 10, 2026 00:19
@wtgodbe
wtgodbe requested a review from BrennanConroy as a code owner June 10, 2026 00:19
@github-actions github-actions Bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Jun 10, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR tightens HTTP/2 and HTTP/3 :path validation in Kestrel to prevent non-ASCII characters from being incorrectly handled during path decoding/normalization, and adds regression tests to ensure the connection/stream is aborted when invalid :path values are received.

Changes:

  • Add runtime validation in HTTP/2 and HTTP/3 stream path parsing to reject characters that don’t safely round-trip into the byte buffer used by the path decoder.
  • Add HTTP/2 and HTTP/3 functional tests that construct HPACK/QPACK header blocks containing invalid :path values and assert the stream is reset/aborted with the expected protocol error.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/Servers/Kestrel/test/InMemory.FunctionalTests/Http3/Http3StreamTests.cs Adds a regression test for invalid non-ASCII :path values sent via QPACK.
src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2StreamTests.cs Adds a regression test for invalid non-ASCII :path values sent via HPACK.
src/Servers/Kestrel/Core/src/Internal/Http3/Http3Stream.cs Adds runtime rejection of invalid characters while building the path byte buffer.
src/Servers/Kestrel/Core/src/Internal/Http2/Http2Stream.cs Adds runtime rejection of invalid characters while building the path byte buffer.

Comment on lines +444 to +448
if (ch > byte.MaxValue)
{
ResetAndAbort(new ConnectionAbortedException(CoreStrings.FormatHttp2StreamErrorPathInvalid(RawTarget)), Http2ErrorCode.PROTOCOL_ERROR);
return false;
}
Comment on lines +1222 to +1226
if (ch > byte.MaxValue)
{
Abort(new ConnectionAbortedException(CoreStrings.FormatHttp3StreamErrorPathInvalid(RawTarget)), Http3ErrorCode.ProtocolError);
return false;
}
Comment on lines +259 to +261
[InlineData("/\u0161dmin?x=1")] // U+0161 (353), truncates to 0x61 = 'a' → "/admin?x=1"
[InlineData("/\u0170ser")] // U+0170 (368), truncates to 0x70 = 'p' → "/pser"
[InlineData("/caf\u0165?q=1")] // U+0165 (357), truncates to 0x65 = 'e' → "/cafe?q=1
@wtgodbe

wtgodbe commented Jun 10, 2026

Copy link
Copy Markdown
Member Author

/ba-g unrelated mac failure

@wtgodbe
wtgodbe merged commit 0fdad03 into main Jun 10, 2026
25 of 28 checks passed
@wtgodbe
wtgodbe deleted the wtgodbe/ascii branch June 10, 2026 04:06
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 17, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants