Skip to content

Add IPv6 scope ID handling in Uri and related tests - #135617

Open
makazeu wants to merge 6 commits into
dotnet:mainfrom
makazeu:fix-uri-ipv6-scope
Open

makazeu wants to merge 6 commits into
dotnet:mainfrom
makazeu:fix-uri-ipv6-scope

Conversation

@makazeu

@makazeu makazeu commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Uri.Equals and Uri.GetHashCode use a cached representation based on UriComponents.HttpRequestUrl, which omits IPv6 scope IDs. Consequently, URIs such as http://[fe80::1%1]/ and http://[fe80::1%2]/ can compare equal despite identifying different local network zones.

This affects consumers that use Uri as a key. In SocketsHttpHandler, changing a proxy's IPv6 scope can reuse the previous proxy's connection pool and select the wrong connection endpoint. This change fixes URI identity at the source rather than introducing a handler-specific workaround.

Approach

  • Compare IPv6 scope IDs separately and include them in the hash for simple parsers, including built-in parsers and directly registered standard parser types.
  • Compare scope text ordinally, distinguishing different scopes and an absent scope from %0, without resolving interface names or normalizing scope values.
  • Prevent the case-insensitive file-URI raw comparison shortcut from treating differently cased scope IDs as equal, while preserving existing file-path comparison behavior.
  • Require matching parsers for string-equality shortcuts, since registering a parser between URI creations can give identical strings different identity semantics.
  • Preserve non-simple parser behavior. These parsers can supply HttpRequestUrl without initializing the host or scope cache; including that lazy cache could change a URI's hash after accessing host properties.

HttpRequestUrl continues to omit scope IDs. Scope identifies a local network zone and is needed for connection selection, but should not be transmitted as part of an outgoing HTTP URI. The fix separates local URI identity from that request representation.

Testing

Validated in Ubuntu 24.04 ARM64 Docker:

  • ./build.sh clr+libs -rc Release and the updated URI library build passed.
  • URI and HTTP functional/unit suites: 22,810 passed, 67 skipped, 0 failed, including the HTTP and SOCKS5 proxy regressions.
  • Late-parser-registration regression: 2 expected failures before the shortcut fix; all 4 cases passed after it.

Resolves #135103

Note

This description was generated with GitHub Copilot.

@makazeu
makazeu marked this pull request as ready for review October 12, 2026 08:19
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

1 similar comment
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Oct 12, 2026
MihaZupan and others added 2 commits October 27, 2026 23:19
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

# Conflicts:
#	src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Net community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent handling of IPv6 scope in SocketsHttpHandler's connection pool

2 participants