remote: validate foreign layer URLs to prevent SSRF#2259
Closed
AlexJohnWilcox wants to merge 3 commits into
Closed
remote: validate foreign layer URLs to prevent SSRF#2259AlexJohnWilcox wants to merge 3 commits into
AlexJohnWilcox wants to merge 3 commits into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Foreign layer descriptors in image manifests can contain arbitrary URLs in the "urls" field. When the registry blob endpoint returns 404, the client fetches these URLs with no validation, allowing a malicious registry to trigger requests to internal services (SSRF). Add validateForeignURL() to reject foreign layer URLs that use non-HTTP(S) schemes or reference private, loopback, link-local, or unspecified IP addresses. This is consistent with the existing validateRealmURL() protection added in PR #2243 for Bearer auth realm URLs. DNS-based SSRF remains out of scope, matching the design decision in validateRealmURL().
validateRealmURL blocks loopback, private, and link-local IP literals but does not check for unspecified addresses (0.0.0.0, [::]). These addresses pass all four existing checks but connect to localhost on Linux and macOS. Add ip.IsUnspecified() to close this gap.
ed3d202 to
9f6bd52
Compare
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## main #2259 +/- ##
===========================================
- Coverage 71.67% 53.05% -18.63%
===========================================
Files 123 165 +42
Lines 9935 11219 +1284
===========================================
- Hits 7121 5952 -1169
- Misses 2115 4555 +2440
- Partials 699 712 +13 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Subserial
pushed a commit
that referenced
this pull request
May 14, 2026
) * remote: validate foreign layer URLs to prevent SSRF Foreign layer descriptors in OCI/Docker manifests may carry arbitrary URLs in the descriptor's "urls" field. When the registry blob endpoint returns 404, the client fetches these URLs directly with no validation, allowing a malicious registry to point them at internal services (e.g. the cloud instance-metadata endpoint 169.254.169.254). Add validateForeignURL, which applies the same scheme and private-IP checks as transport.validateRealmURL to every foreign layer URL before making a network request. HTTP is only permitted when the registry itself was reached over HTTP (insecure=true). DNS-based SSRF remains out of scope, consistent with the design decision in validateRealmURL. Fixes #2259. * remote: block SSRF redirect bypass for foreign layer URLs The previous fix validates each foreign layer URL with validateForeignURL before adding it to the fetch list. However, http.Client follows redirects by default: an attacker can host a foreign layer URL on a public domain that passes the initial check, then redirect the client to http://169.254.169.254/... (AWS/GCP instance-metadata), leaking cloud credentials. Add fetchForeignBlobURL (on *fetcher) that reuses the existing transport but sets a CheckRedirect hook calling validateForeignURL on every redirect hop. Compressed() now routes foreign layer fetches through this method instead of the shared fetchBlobURL so that the validation happens at both the initial URL and each redirect destination. New tests: - TestPullingForeignLayerSSRFViaRedirect: attacker httptest server issues a 302 to a loopback victim; confirms Compressed() returns an error before any credentials are returned. * remote: move foreign layer SSRF helpers to fetcher.go per review Move validateForeignURL and fetchForeignBlobURL (plus their tests) next to the fetcher receiver, trim verbose function comments, and rework Compressed() to call fetchBlobURL on the single registry URL with foreign URLs collected and iterated separately. * remote: rename unused params to satisfy revive linter
Subserial
pushed a commit
to Subserial/go-containerregistry
that referenced
this pull request
May 15, 2026
… (google#2293) * remote: validate foreign layer URLs to prevent SSRF Foreign layer descriptors in OCI/Docker manifests may carry arbitrary URLs in the descriptor's "urls" field. When the registry blob endpoint returns 404, the client fetches these URLs directly with no validation, allowing a malicious registry to point them at internal services (e.g. the cloud instance-metadata endpoint 169.254.169.254). Add validateForeignURL, which applies the same scheme and private-IP checks as transport.validateRealmURL to every foreign layer URL before making a network request. HTTP is only permitted when the registry itself was reached over HTTP (insecure=true). DNS-based SSRF remains out of scope, consistent with the design decision in validateRealmURL. Fixes google#2259. * remote: block SSRF redirect bypass for foreign layer URLs The previous fix validates each foreign layer URL with validateForeignURL before adding it to the fetch list. However, http.Client follows redirects by default: an attacker can host a foreign layer URL on a public domain that passes the initial check, then redirect the client to http://169.254.169.254/... (AWS/GCP instance-metadata), leaking cloud credentials. Add fetchForeignBlobURL (on *fetcher) that reuses the existing transport but sets a CheckRedirect hook calling validateForeignURL on every redirect hop. Compressed() now routes foreign layer fetches through this method instead of the shared fetchBlobURL so that the validation happens at both the initial URL and each redirect destination. New tests: - TestPullingForeignLayerSSRFViaRedirect: attacker httptest server issues a 302 to a loopback victim; confirms Compressed() returns an error before any credentials are returned. * remote: move foreign layer SSRF helpers to fetcher.go per review Move validateForeignURL and fetchForeignBlobURL (plus their tests) next to the fetcher receiver, trim verbose function comments, and rework Compressed() to call fetchBlobURL on the single registry URL with foreign URLs collected and iterated separately. * remote: rename unused params to satisfy revive linter
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.
Summary
Foreign layer descriptors in OCI/Docker image manifests can contain arbitrary URLs in the
urlsfield (OCI Image Spec). When the registry blob endpoint returns 404, the client fetches these foreign URLs with no validation. A malicious registry can serve manifests with foreign layer URLs pointing to internal services (e.g. cloud metadata at169.254.169.254, RFC 1918 addresses), causing SSRF from any library consumer.This PR adds two fixes:
1. Foreign layer URL validation (
pkg/v1/remote/image.go)Adds
validateForeignURL()to reject foreign layer URLs that:ftp://,file://, etc.)This is consistent with the existing
validateRealmURL()protection added in #2243 for Bearer auth realm URLs. DNS-based SSRF remains out of scope, matching the design decision invalidateRealmURL().2.
IsUnspecifiedgap invalidateRealmURL(pkg/v1/remote/transport/bearer.go)validateRealmURL()checksIsLoopback,IsPrivate,IsLinkLocalUnicast, andIsLinkLocalMulticastbut notIsUnspecified. The addresses0.0.0.0and[::]pass all four checks but connect to localhost on Linux/macOS. Addsip.IsUnspecified()to close this gap.Test plan
TestValidateForeignURL— table-driven unit test (12 cases covering public, private, loopback, link-local, unspecified IPs and disallowed schemes)TestPullingForeignLayerSSRF— integration test that verifies pulling an image with a foreign layer URL pointing to169.254.169.254is rejectedTestValidateRealmURL— table-driven unit test (11 cases including0.0.0.0and[::])TestPullingForeignLayerupdated and passinggo test ./pkg/v1/remote/ ./pkg/v1/remote/transport/passes