-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Uri.TryCreate (and ctor) behave weird when using the IPv6 format #97939
Comments
Tagging subscribers to this area: @dotnet/ncl Issue DetailsDescriptionWhen using the IPv6 format for the host and it contains a % with other stuff at the end of the IPv6 block
Reproduction Stepsif (Uri.TryCreate("http://[::1%zyx]:8080/", UriKind.Absolute, out Uri uri))
{
Console.WriteLine(uri.Authority);
Console.WriteLine(uri.Host);
Console.WriteLine(uri.IdnHost);
Console.WriteLine(uri.GetLeftPart(UriPartial.Authority));
Console.WriteLine(uri.AbsoluteUri);
Console.WriteLine(uri.HostNameType);
}
else
{
Console.WriteLine("Invalid");
}
Expected behaviorI would expect the provided input to be seen as invalid (similar as is done with the "IPv4" version http://127.0.0.1%zyx:8080/). If it is considered a valid format, I would expect the uri properties / method results to be consistent and not omit part of the user input Actual behaviorSee the description / repro steps Regression?I only checked the behavior on .NET 6/7/8 and they all seems to show the same behavior Known WorkaroundsNo response Configuration8.0.100 Other informationI have a feeling it might be related to #45194. If this is the case however since in the URI format IPv6 is encapsulated in the [] I would expect the validation of URI to be stricter
|
For IPv6 the |
Ah, I was not aware this was a separate RFC, so that explain a lot. However it is certainly unexpected that input is whiped away for some properties and not others. From a breaking change perspective, maybe it would be worth it to extend UriCreationOptions with a or several options to reject such values so you can opt-in to having a more predictable behavior/outcome. (maybe it could even be made in such a way you can specify to only allow a domain, or IPv4 or IPv6 (with or without ScopeId) etc) |
Is this causing you actual problems, or was it just an inconsistency you noticed? While we don't like the inconsistency, changing behavior here would break people.
What would the use case be here? |
This issue has been marked |
The reason I proposed the addition(s) to the UriCreationOptions is because I was under the impression that the UriCreationOptions overload was created to make it possible to extend the options in an opt-in manner not introducing breaking changes to the behavior. The reason I encountered it is because I was looking into the OWASP SSRF prevention Case 2 and it mentions DNS pinning (or rebinding) and though about implement such a strategy through the SocketsHttpHandler::ConnectCallback callback. In that callback an DnsEndPoint is provided and I was putting the code through some fuzzing tests which caught this scenario. Later I found out that the DnsEndpoint is created in several steps Uri.IdnHost => HttpConnectionKey => HttpAuthority => DnsEndpoint, and the DnsEndpoint provided does not have the AddressFamily set, though HttpAuthority handles IPv6 specially and wraps it. Uri.IdnHost has this remark about unescaping however DnsEndpoint does not have such a remark, it is not very easy to figure out in my opinion. |
Description
When using the IPv6 format for the host and it contains a % with other stuff at the end of the IPv6 block
Reproduction Steps
Expected behavior
I would expect the provided input to be seen as invalid (similar as is done with the "IPv4" version http://127.0.0.1%zyx:8080/).
If it is considered a valid format, I would expect the uri properties / method results to be consistent and not omit part of the user input
Actual behavior
See the description / repro steps
Regression?
I only checked the behavior on .NET 6/7/8 and they all seems to show the same behavior
Known Workarounds
No response
Configuration
8.0.100
Windows 11 23H2 22631.3007
x64
I didn't check any other configurations
Other information
I have a feeling it might be related to #45194. If this is the case however since in the URI format IPv6 is encapsulated in the [] I would expect the validation of URI to be stricter
The text was updated successfully, but these errors were encountered: