Fix preserving %2F at HTTP/1 absolute-form request#65930
Open
DeagleGross wants to merge 6 commits intodotnet:mainfrom
Open
Fix preserving %2F at HTTP/1 absolute-form request#65930DeagleGross wants to merge 6 commits intodotnet:mainfrom
DeagleGross wants to merge 6 commits intodotnet:mainfrom
Conversation
…ute-form When processing HTTP/1.1 absolute-form request targets (e.g., GET http://host/a%2Fb), Kestrel used Uri.LocalPath to extract the path, which decodes %2F to '/'. This differed from origin-form handling which uses PathDecoder.DecodePath that deliberately preserves %2F. Replace Uri.LocalPath with Uri.AbsolutePath (which preserves percent- encoding) followed by PathDecoder.DecodePath, ensuring both request- target forms produce identical HttpRequest.Path values. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ute-form When processing HTTP/1.1 absolute-form request targets (e.g., GET http://host/a%2Fb), Kestrel used Uri.LocalPath to extract the path, which decodes %2F to '/'. This differed from origin-form handling which uses PathDecoder.DecodePath that deliberately preserves %2F. Replace Uri.LocalPath with Uri.AbsolutePath (which preserves percent- encoding) followed by PathDecoder.DecodePath, ensuring both request- target forms produce identical HttpRequest.Path values. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
https://github.com/DeagleGross/aspnetcore into dmkorolev/kestrel-absolute-form-path-canonicalization # Conflicts: # src/Servers/Kestrel/Core/src/Internal/Http/Http1Connection.cs
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an inconsistency in Kestrel HTTP/1.1 request-target parsing so that an encoded slash (%2F) is preserved in HttpRequest.Path for absolute-form targets, matching origin-form (and aligning with HTTP/2/3 path decoding behavior).
Changes:
- Add StartLineTests coverage for
%2Fpreservation in both origin-form and absolute-form request-targets. - Update
Http1Connection.OnAbsoluteFormTargetto derivePathviaPathDecoder.DecodePath(usingUri.AbsolutePath) instead ofuri.LocalPath, avoiding%2Fbeing decoded to/.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Servers/Kestrel/Core/test/StartLineTests.cs | Adds test cases validating %2F stays encoded in Path for origin-form and absolute-form. |
| src/Servers/Kestrel/Core/src/Internal/Http/Http1Connection.cs | Switches absolute-form path materialization from Uri.LocalPath to PathDecoder.DecodePath over Uri.AbsolutePath to preserve %2F. |
BrennanConroy
approved these changes
Mar 23, 2026
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.
Fixes an inconsistency in HTTP/1.1 request-target parsing where
%2Fin the path produces differentHttpRequest.Path values depending on the request-target form: