- 
                Notifications
    
You must be signed in to change notification settings  - Fork 5.2k
 
Add URL scheme validation for HTTP redirects in SocketsHttpHandler #121263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: MihaZupan <[email protected]>
| 
           Tagging subscribers to this area: @dotnet/ncl  | 
    
There was a problem hiding this comment.
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 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
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
        
          
                src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.AutoRedirect.cs
              
                Outdated
          
            Show resolved
            Hide resolved
        
      …chemes Co-authored-by: MihaZupan <[email protected]>
| 
           /ba-g android timing out  | 
    
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.