Add URL scheme validation for HTTP redirects in SocketsHttpHandler#121263
Merged
Add URL scheme validation for HTTP redirects in SocketsHttpHandler#121263
Conversation
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add validation for request URL scheme on redirects
Add URL scheme validation for HTTP redirects in SocketsHttpHandler
Nov 1, 2025
Open
3 tasks
MihaZupan
approved these changes
Nov 1, 2025
Contributor
|
Tagging subscribers to this area: @dotnet/ncl |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds a security enhancement to block automatic HTTP redirects to unsupported URI schemes (ftp, file, gopher, telnet, etc.). The changes prevent potential security issues where a malicious server could redirect an HTTP/HTTPS request to a different protocol scheme.
- Adds a check in
RedirectHandler.GetUriForRedirectto validate the redirect location scheme - Returns the original redirect response (302, 307, etc.) instead of following unsafe redirects
- Includes comprehensive test coverage for multiple unsupported schemes
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| RedirectHandler.cs | Adds unsupported scheme validation before processing redirects |
| HttpClientHandlerTest.AutoRedirect.cs | Adds test cases validating that redirects to ftp, file, gopher, and telnet schemes are blocked |
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/RedirectHandler.cs
Show resolved
Hide resolved
stephentoub
approved these changes
Nov 2, 2025
src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.AutoRedirect.cs
Outdated
Show resolved
Hide resolved
…chemes Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
This was referenced Nov 3, 2025
MihaZupan
approved these changes
Nov 3, 2025
Member
|
/ba-g android timing out |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Add URL Scheme Validation on Redirects
This PR adds missing URL scheme validation when following HTTP redirects in SocketsHttpHandler.
Problem:
Solution:
Add the same
IsSupportedSchemevalidation inRedirectHandler.GetUriForRedirect()after the existing https->http downgrade check. When a redirect to an unsupported scheme is detected:HttpRequestExceptionwith innerWinHttpException(error 12156)Changes:
Testing:
Checklist:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.