Repository navigation
Use AntiSSRF to validate container auth realm connections - #56843
Merged
Merged
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 2 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new token-request transport disables proxy support even for the explicit None opt-out, breaking proxy-only authentication, while removed normalization-sensitive SSRF tests leave important regression gaps.
2 open issues
1 file not reviewed
src/Containers/Microsoft.NET.Build.Containers/Resources/Strings.Designer.cs: Generated file
What changed in this PR
This PR moves container registry token requests to a dedicated AntiSSRF transport that validates resolved addresses when connecting. Internal token endpoints now require explicit address-policy configuration rather than the previous insecure-registry exceptions.
Changes:
- Adds
Public,AllowlistOnly, andNonepolicies with configurable IP/CIDR exceptions. - Preserves HTTPS downgrade protection and reports policy/configuration failures through container diagnostics.
- Updates dependency packaging, regression tests, localization resources, and contributor guidance.
| File | Description |
|---|---|
| test/Microsoft.NET.Build.Containers.UnitTests/ImagePublisherTests.cs | Tests configuration diagnostics and suppressed success telemetry. |
| test/Microsoft.NET.Build.Containers.UnitTests/AuthRealmHandlerFactoryTests.cs | Tests policies, connections, redirects, and exception translation. |
| test/Microsoft.NET.Build.Containers.UnitTests/AuthHandshakeMessageHandlerTests.cs | Tests separate token transport and diagnostic propagation. |
| test/Microsoft.NET.Build.Containers.IntegrationTests/PackageTests.cs | Verifies AntiSSRF dependency packaging. |
| src/Containers/packaging/package.csproj | Includes AntiSSRF in packaged task dependencies. |
| src/Containers/Microsoft.NET.Build.Containers/Tasks/CreateNewImage.cs | Reports invalid realm configuration as container diagnostics. |
| src/Containers/Microsoft.NET.Build.Containers/Resources/xlf/Strings.zh-Hant.xlf | Updates Traditional Chinese localization entries. |
| src/Containers/Microsoft.NET.Build.Containers/Resources/xlf/Strings.zh-Hans.xlf | Updates Simplified Chinese localization entries. |
| src/Containers/Microsoft.NET.Build.Containers/Resources/xlf/Strings.tr.xlf | Updates Turkish localization entries. |
| src/Containers/Microsoft.NET.Build.Containers/Resources/xlf/Strings.ru.xlf | Updates Russian localization entries. |
| src/Containers/Microsoft.NET.Build.Containers/Resources/xlf/Strings.pt-BR.xlf | Updates Brazilian Portuguese localization entries. |
| src/Containers/Microsoft.NET.Build.Containers/Resources/xlf/Strings.pl.xlf | Updates Polish localization entries. |
| src/Containers/Microsoft.NET.Build.Containers/Resources/xlf/Strings.ko.xlf | Updates Korean localization entries. |
| src/Containers/Microsoft.NET.Build.Containers/Resources/xlf/Strings.ja.xlf | Updates Japanese localization entries. |
| src/Containers/Microsoft.NET.Build.Containers/Resources/xlf/Strings.it.xlf | Updates Italian localization entries. |
| src/Containers/Microsoft.NET.Build.Containers/Resources/xlf/Strings.fr.xlf | Updates French localization entries. |
| src/Containers/Microsoft.NET.Build.Containers/Resources/xlf/Strings.es.xlf | Updates Spanish localization entries. |
| src/Containers/Microsoft.NET.Build.Containers/Resources/xlf/Strings.de.xlf | Updates German localization entries. |
| src/Containers/Microsoft.NET.Build.Containers/Resources/xlf/Strings.cs.xlf | Updates Czech localization entries. |
| src/Containers/Microsoft.NET.Build.Containers/Resources/Strings.resx | Defines policy-blocking and configuration error messages. |
| src/Containers/Microsoft.NET.Build.Containers/Resources/Strings.Designer.cs | Exposes generated accessors for updated resources. |
| src/Containers/Microsoft.NET.Build.Containers/Registry/RegistrySettings.cs | Defines the two policy environment variables. |
| src/Containers/Microsoft.NET.Build.Containers/Registry/Registry.cs | Excludes authentication errors from retry/fallback catches. |
| src/Containers/Microsoft.NET.Build.Containers/Registry/DefaultRegistryAPI.cs | Makes host-specific certificate validation reusable internally. |
| src/Containers/Microsoft.NET.Build.Containers/Microsoft.NET.Build.Containers.csproj | References AntiSSRF. |
| src/Containers/Microsoft.NET.Build.Containers/ImagePublisher.cs | Reports configuration errors and gates success telemetry. |
| src/Containers/Microsoft.NET.Build.Containers/Exceptions/InvalidAuthRealmConfigurationException.cs | Carries configuration diagnostic details. |
| src/Containers/Microsoft.NET.Build.Containers/AuthRealmHandlerFactory.cs | Implements policy configuration and protected token transport. |
| src/Containers/Microsoft.NET.Build.Containers/AuthHandshakeMessageHandler.cs | Routes token requests through the dedicated transport. |
| src/Containers/AGENTS.md | Documents token transport and policy requirements. |
| Directory.Packages.props | Pins the AntiSSRF package version. |
Review effort: Balanced
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
lbussell
approved these changes
Nov 2, 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
Use
Microsoft.Security.AntiSSRFfor container registry token requests. The authentication realm is the token endpoint URL supplied by the registry in its bearer authentication challenge. Its hostname is resolved and the resulting addresses are validated when a connection is opened.Adds two environment variables to configure the address policy, including support for internal token endpoints:
DOTNET_CONTAINER_AUTH_REALM_POLICYSelects which addresses token requests may connect to.
Public(default): Allows addresses outside the library’s private and special-use exclusions, plus any explicitly allowed addresses.AllowlistOnly: Allows only explicitly configured IP addresses and CIDR ranges. An empty allowlist permits no connections.None: Applies no address restrictions. Existing HTTP/HTTPS requirements still apply.DOTNET_CONTAINER_AUTH_REALM_ALLOWED_ADDRESSESA semicolon-separated list of IPv4/IPv6 addresses or CIDR ranges, for example:
With
Public, these entries add exceptions to the default address exclusions. WithAllowlistOnly, they define the complete set of permitted addresses.