Description
We've made a handful of minor breaking changes to Uri in .NET 11, I'm merging them as one issue since they're all rather niche.
PRs:
Version
.NET 11 GA
Previous behavior
- A Uri string without a delimiter between an IPv6 address and the path, such as
"http://[::]extra", would be parsed the same if it had a delimiter "http://[::]/extra".
- The
UriBuilder.Host setter allowed values such as "contoso.com/path", potentially altering other Uri components after the builder combined values together via ToString/Uri.
- Uri allowed parsing of IPv6 length prefixes, such as the
"/64" in "http://[AB::/64]/path".
- Uri allowed an octal value in the last segment of an IPv4 address embedded in IPv6. E.g.
"http://[::1.2.3.04]/" would be parsed while "http://[::1.2.03.4]/" would be rejected.
- There was an inconsistency between how
new Uri("p%41th", UriKind.Relative) and Uri.TryCreate("p%41th", UriKind.Relative, out uri) behaved. The constructor would normalize the input to "pAth", while the TryCreate factory would leave it as-is.
New behavior
- Parsing will enforce that a delimiter is present after an IPv6 address. Parsing
"http://[::]extra" now fails.
- The
UriBuilder.Host setter now performs best-effort validation and rejects inputs that would alter other components. Setting the property to a value such as "contoso.com/path" or "user@host" now throws. Some other invalid inputs are now also caught early, such as some forms of invalid IPv6 addresses, e.g. "[127.0.0.1]". It is still possible that constructing the combined Uri will throw an exception for an invalid host even if the UriBuilder.Host property setter did not throw.
- If a IPv6 length prefix is present in the input, Uri parsing will now fail. The set of characters allowed in the zone ID (scope) is also more restricted.
- Octal values are now rejected in any position of an embedded IPv4 address. Parsing
"http://[::1.2.3.04]/" will now fail.
- Normalization applied by
new Uri(value, UriKind.Relative) and Uri.TryCreate(value, UriKind.Relative, out uri) is now the same. Processing "p%41th" through either will normalize the value to "pAth".
Type of breaking change
Reason for change
Stricter adherence to the Uri spec and reducing parsing inconsistencies.
For more details about the design and security considerations of Uri and UriBuilder, review the following threat model documents:
Recommended action
It is unlikely that any changes should be made by your application code as a response to these changes.
If you are currently relying on setting multiple Uri components through the UriBuilder.Host setter, change the application logic to set individual components instead.
Feature area
Networking
Affected APIs
All Uri constructors / TryCreate factories + UriBuilder.Host.
Associated WorkItem - 628409
Description
We've made a handful of minor breaking changes to Uri in .NET 11, I'm merging them as one issue since they're all rather niche.
PRs:
Version
.NET 11 GA
Previous behavior
"http://[::]extra", would be parsed the same if it had a delimiter"http://[::]/extra".UriBuilder.Hostsetter allowed values such as"contoso.com/path", potentially altering other Uri components after the builder combined values together viaToString/Uri."/64"in"http://[AB::/64]/path"."http://[::1.2.3.04]/"would be parsed while"http://[::1.2.03.4]/"would be rejected.new Uri("p%41th", UriKind.Relative)andUri.TryCreate("p%41th", UriKind.Relative, out uri)behaved. The constructor would normalize the input to"pAth", while theTryCreatefactory would leave it as-is.New behavior
"http://[::]extra"now fails.UriBuilder.Hostsetter now performs best-effort validation and rejects inputs that would alter other components. Setting the property to a value such as"contoso.com/path"or"user@host"now throws. Some other invalid inputs are now also caught early, such as some forms of invalid IPv6 addresses, e.g."[127.0.0.1]". It is still possible that constructing the combined Uri will throw an exception for an invalid host even if theUriBuilder.Hostproperty setter did not throw."http://[::1.2.3.04]/"will now fail.new Uri(value, UriKind.Relative)andUri.TryCreate(value, UriKind.Relative, out uri)is now the same. Processing"p%41th"through either will normalize the value to"pAth".Type of breaking change
Reason for change
Stricter adherence to the Uri spec and reducing parsing inconsistencies.
For more details about the design and security considerations of
UriandUriBuilder, review the following threat model documents:Recommended action
It is unlikely that any changes should be made by your application code as a response to these changes.
If you are currently relying on setting multiple Uri components through the
UriBuilder.Hostsetter, change the application logic to set individual components instead.Feature area
Networking
Affected APIs
All Uri constructors / TryCreate factories +
UriBuilder.Host.Associated WorkItem - 628409