Skip to content

Use AntiSSRF to validate container auth realm connections - #56843

Merged
mthalman merged 2 commits into
mainfrom
dev/mthalman/container-antissrf-validation
Nov 2, 2026
Merged

mthalman merged 2 commits into
mainfrom
dev/mthalman/container-antissrf-validation

Conversation

@mthalman

Copy link
Copy Markdown
Member

Description

Use Microsoft.Security.AntiSSRF for 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_POLICY

Selects 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_ADDRESSES

A semicolon-separated list of IPv4/IPv6 addresses or CIDR ranges, for example:

10.20.30.40;10.50.0.0/16;fd00::/8

With Public, these entries add exceptions to the default address exclusions. With AllowlistOnly, they define the complete set of permitted addresses.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 29, 2026 21:00
@mthalman
mthalman requested review from a team and lbussell as code owners October 29, 2026 21:00
@azure-pipelines

Copy link
Copy Markdown
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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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, and None policies 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>
@mthalman
mthalman merged commit 2a3c360 into main Nov 2, 2026
30 of 31 checks passed
@mthalman
mthalman deleted the dev/mthalman/container-antissrf-validation branch November 2, 2026 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants