Initialize WebProxy credentials from URI UserInfo#125384
Open
Initialize WebProxy credentials from URI UserInfo#125384
Conversation
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix WebProxy not initializing credentials from Proxy URL
Initialize WebProxy credentials from URI UserInfo
Mar 10, 2026
Contributor
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
MihaZupan
reviewed
Mar 10, 2026
…dd ctor remarks Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
MihaZupan
reviewed
Mar 10, 2026
…opServices ref (needed for SecureString) Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates System.Net.WebProxy so that when a proxy Uri contains embedded credentials in its UserInfo (e.g., scheme://user:pass@host:port), WebProxy automatically initializes its Credentials from that information, improving parity with common proxy URI expectations (notably for SOCKS authentication).
Changes:
- Updated
WebProxy.Addresssetter (and thus constructors that setAddress) to extractNetworkCredentialfromUri.UserInfowith percent-decoding. - Ensured explicit
Credentialspassed to constructors still take precedence over URI-extracted credentials. - Added comprehensive unit tests covering constructor and setter behavior, encoding edge cases, and precedence rules.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/libraries/System.Net.WebProxy/src/System/Net/WebProxy.cs |
Extracts credentials from Address Uri.UserInfo and applies precedence rules when explicit credentials are provided. |
src/libraries/System.Net.WebProxy/tests/WebProxyTest.cs |
Adds 23 test cases validating credential extraction, decoding, null/no-userinfo handling, and precedence behavior. |
src/libraries/System.Net.WebProxy/src/System.Net.WebProxy.csproj |
Adds an explicit System.Runtime.InteropServices project reference to support NetworkCredential’s SecureString-related surface. |
This was referenced Mar 10, 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.
Description
WebProxyignores credentials embedded in proxy URIs (e.g.,******host:1080). TheUserInfocomponent is never parsed, soCredentialsstaysnull— causing SOCKS5 auth failures and forcing users to set credentials separately.Changes:
Addressproperty setter now extractsNetworkCredentialfromUri.UserInfowhen present, usingUri.UnescapeDataStringfor proper percent-decoding. Uses the C#fieldkeyword to avoid an explicit backing field.Credentialsparameter still takes precedenceGetCredentialsFromUrihelper (follows the same pattern asHttpEnvironmentProxy.GetCredentialsFromString)System.Runtime.InteropServicesproject reference (required bySecureStringused internally byNetworkCredential)<remarks>on theAddressproperty and all constructors that accept an address (bothUri?andstring?overloads) documenting the automatic credential extraction behaviorBoth paths now work equivalently:
23 new test cases covering constructor and setter paths, URL-encoded special characters, explicit credential precedence, and null/no-userinfo edge cases.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.