Skip to content

Reject literal fragments in Kestrel request targets - #70578

Merged
wtgodbe merged 1 commit into
dotnet:mainfrom
elinor-fung:reject-request-target-fragment
Nov 16, 2026
Merged

wtgodbe merged 1 commit into
dotnet:mainfrom
elinor-fung:reject-request-target-fragment

Conversation

@elinor-fung

Copy link
Copy Markdown
Member

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). Make Kestrel reject targets containing it.

Microsoft.AspNetCore.Server.Kestrel.AllowFragmentInRequestTarget AppContext switch opts back in to accepting a literal #.

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]>
Copilot AI balanced review requested due to automatic review settings November 13, 2026 17:24
@github-actions github-actions Bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Nov 13, 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.

🟢 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.AllowFragmentInRequestTarget AppContext 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

@PureWeen

Copy link
Copy Markdown
Member

/review

@wtgodbe
wtgodbe merged commit 5e14b54 into dotnet:main Nov 16, 2026
30 checks passed
@wtgodbe
wtgodbe temporarily deployed to copilot-pat-pool November 16, 2026 19:53 — with GitHub Actions Inactive
@wtgodbe
wtgodbe temporarily deployed to copilot-pat-pool November 16, 2026 19:53 — with GitHub Actions Inactive
@wtgodbe
wtgodbe temporarily deployed to copilot-pat-pool November 16, 2026 19:54 — with GitHub Actions Inactive
@wtgodbe
wtgodbe temporarily deployed to copilot-pat-pool November 16, 2026 19:56 — with GitHub Actions Inactive
@wtgodbe
wtgodbe temporarily deployed to copilot-pat-pool November 16, 2026 19:59 — with GitHub Actions Inactive
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Documentation appears necessary, but a draft PR could not be created.

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

  • Conceptual article: Not required — No public API added; the internal option is exposed only via an AppContext switch, documented in the breaking-change article.
  • Migration guidance: Not required — Remediation is covered concisely in the breaking-change article; no migration directory exists.
  • Breaking change: Required — Kestrel now rejects request targets with a literal '#' (Http1Connection, Http2Stream, Http3Stream); previously accepted requests fail unless the AppContext switch is set.

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 38cb94c6 Deployed Nov 16, 2026 by wtgodbe via conclusion #341
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.

5 participants