Repository navigation
Reject literal fragments in Kestrel request targets - #70578
Merged
Merged
Conversation
Literal `#` is not permitted by the path and query grammar for request targets (`origin-form` and `absolute-form` for HTTP/1.x, `:path` for HTTP/2 and HTTP/3). Kestrel now rejects targets containing it. Adds the `Microsoft.AspNetCore.Server.Kestrel.AllowFragmentInRequestTarget` AppContext switch to opt back in to accepting a literal `#`. Port of dotnet-dotnet internal PRs 66711 and 67076. Co-authored-by: Copilot App <[email protected]>
elinor-fung
requested review from
BrennanConroy,
SamMonoRT and
halter73
as code owners
November 13, 2026 17:24
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the request-target fragment handling change.
No open issues 🎉
What changed in this PR
This PR updates Kestrel to reject literal # characters in HTTP/1.x origin-form and absolute-form request targets and HTTP/2 and HTTP/3 :path values.
Changes:
- Rejects literal fragments before request-target decoding.
- Adds the
Microsoft.AspNetCore.Server.Kestrel.AllowFragmentInRequestTargetAppContext switch to restore acceptance. - Adds tests for rejection, switch-enabled acceptance, and continued support for percent-encoded
%23.
| File | Description |
|---|---|
| src/Servers/Kestrel/test/InMemory.FunctionalTests/RequestTargetProcessingTests.cs | Tests HTTP/1.x encoded fragments and switch-enabled acceptance. |
| src/Servers/Kestrel/test/InMemory.FunctionalTests/Http3/Http3StreamTests.cs | Tests HTTP/3 rejection, encoded fragments, and opt-in acceptance. |
| src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2StreamTests.cs | Tests HTTP/2 rejection, encoded fragments, and opt-in acceptance. |
| src/Servers/Kestrel/test/InMemory.FunctionalTests/BadHttpRequestTests.cs | Tests HTTP/1.x bad-request responses for literal fragments. |
| src/Servers/Kestrel/shared/test/HttpParsingData.cs | Supplies shared fragment request-target test cases. |
| src/Servers/Kestrel/Core/src/KestrelServerOptions.cs | Adds the internal option backed by the AppContext switch. |
| src/Servers/Kestrel/Core/src/Internal/Http3/Http3Stream.cs | Rejects literal fragments with an HTTP/3 stream error. |
| src/Servers/Kestrel/Core/src/Internal/Http2/Http2Stream.cs | Rejects literal fragments with an HTTP/2 stream reset. |
| src/Servers/Kestrel/Core/src/Internal/Http/Http1Connection.cs | Rejects literal fragments in origin-form and absolute-form targets. |
Review effort: Balanced
BrennanConroy
approved these changes
Nov 13, 2026
Member
|
/review |
wtgodbe
temporarily deployed
to
copilot-pat-pool
November 16, 2026 19:53 — with
GitHub Actions
Inactive
wtgodbe
temporarily deployed
to
copilot-pat-pool
November 16, 2026 19:53 — with
GitHub Actions
Inactive
wtgodbe
temporarily deployed
to
copilot-pat-pool
November 16, 2026 19:54 — with
GitHub Actions
Inactive
wtgodbe
temporarily deployed
to
copilot-pat-pool
November 16, 2026 19:56 — with
GitHub Actions
Inactive
wtgodbe
had a problem deploying
to
copilot-pat-pool
November 16, 2026 19:58 — with
GitHub Actions
Failure
wtgodbe
temporarily deployed
to
copilot-pat-pool
November 16, 2026 19:59 — with
GitHub Actions
Inactive
Contributor
|
Confidence that documentation is needed: 85% Drafted a breaking-change article for ASP.NET Core 12 describing the new rejection of literal '#' in request targets and the AllowFragmentInRequestTarget opt-out switch. Documentation surfaces considered
|
wtgodbe
temporarily deployed
to
copilot-pat-pool
November 16, 2026 19:59 — with
GitHub Actions
Inactive
3 of 4 tasks
This branch was previously deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Literal
#is not permitted by the path and query grammar for request targets (origin-formandabsolute-formfor HTTP/1.x,:pathfor HTTP/2 and HTTP/3). Make Kestrel reject targets containing it.Microsoft.AspNetCore.Server.Kestrel.AllowFragmentInRequestTargetAppContext switch opts back in to accepting a literal#.