remote: validate foreign layer URLs to prevent SSRF#2259
Open
AlexJohnWilcox wants to merge 3 commits intogoogle:mainfrom
Open
remote: validate foreign layer URLs to prevent SSRF#2259AlexJohnWilcox wants to merge 3 commits intogoogle:mainfrom
AlexJohnWilcox wants to merge 3 commits intogoogle:mainfrom
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 google#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:
|
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