Repository navigation
transport: block redirects from token server to private/link-local addresses (SSRF fix) - #2292
Merged
Subserial merged 4 commits intoMay 13, 2026
Merged
Conversation
refreshOauth and refreshBasic constructed http.Client without a CheckRedirect handler, allowing a malicious token server to issue an HTTP redirect to an internal address (e.g. 169.254.169.254) that would pass the initial validateRealmURL check but still reach private services. Add realmRedirectCheck, which applies the same scheme and private-IP restrictions as validateRealmURL to every redirect hop during a token-fetch request. Wire it as CheckRedirect on both clients. Add TestTokenServerRedirectSSRF to confirm the redirect is rejected.
2 of 4 tasks
Subserial
suggested changes
May 12, 2026
Subserial
left a comment
There was a problem hiding this comment.
This change has some AI assistant hallmarks, so I will be pedantic about comments.
Looks good, just mostly needs to adjust overly-descriptive or inaccurate language.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2292 +/- ##
==========================================
+ Coverage 56.70% 56.74% +0.04%
==========================================
Files 165 165
Lines 11239 11248 +9
==========================================
+ Hits 6373 6383 +10
Misses 4106 4106
+ Partials 760 759 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Shorten realmRedirectCheck doc comment. - Extract allowInsecure local in refreshOauth and refreshBasic. - Drop redundant inline comment in TestTokenServerRedirectSSRF.
Subserial
approved these changes
May 13, 2026
|
LGTM, just need to make the linter happy and I'll merge the PR. Thanks! |
Subserial
pushed a commit
to Subserial/go-containerregistry
that referenced
this pull request
May 15, 2026
…dresses (SSRF fix) (google#2292) * transport: block redirects from token server to private addresses refreshOauth and refreshBasic constructed http.Client without a CheckRedirect handler, allowing a malicious token server to issue an HTTP redirect to an internal address (e.g. 169.254.169.254) that would pass the initial validateRealmURL check but still reach private services. Add realmRedirectCheck, which applies the same scheme and private-IP restrictions as validateRealmURL to every redirect hop during a token-fetch request. Wire it as CheckRedirect on both clients. Add TestTokenServerRedirectSSRF to confirm the redirect is rejected. * transport: address review feedback - Shorten realmRedirectCheck doc comment. - Extract allowInsecure local in refreshOauth and refreshBasic. - Drop redundant inline comment in TestTokenServerRedirectSSRF. * transport: rename unused handler param to satisfy revive linter
Subserial
pushed a commit
that referenced
this pull request
Jun 12, 2026
* fix: prevent SSRF in google.List() pagination Add URL validation to getNextPageURL() to ensure pagination Link headers point to the same registry host. This prevents SSRF attacks where a malicious registry could include a Link header pointing to internal services like cloud metadata endpoints (169.254.169.254). The fix validates that: 1. The pagination URL scheme matches the registry scheme 2. The pagination URL host matches the registry host This is consistent with SSRF protections added in PRs #2292, #2293, #2295 for other code paths. * fix: also prevent SSRF in remote.List() and remote.Catalog() pagination The same SSRF vulnerability that affected google.List() also exists in remote.List() and remote.Catalog(). A malicious registry can return a Link header pointing to internal services. This commit adds SSRF protection to the remote package's pagination handling, using the same validation approach. * fix: update remote list_test.go for getNextPageURL signature change Update test calls to getNextPageURL in pkg/v1/remote/list_test.go to pass the required name.Repository argument, matching the new function signature that includes SSRF validation. Also update makeResp helper to include a Request with URL for proper ResolveReference behavior, and adjust test assertions accordingly. * fix: treat empty Link header URL as no next page * fix: restore missing <> test case and add SSRF test to remote package --------- Co-authored-by: tufstraka <[email protected]>
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
refreshOauthandrefreshBasicinbearer.goconstruct anhttp.Clientwithout aCheckRedirecthandler. Go's default redirect policy follows up to 10 hops unconditionally, forwarding the request to any URL returned by the server including private and link-local addresses.A malicious or compromised token server (or a registry that controls the
realmparameter inWWW-Authenticate) can therefore bypass the existingvalidateRealmURLcheck by first responding with a valid-looking realm URL and then issuing an HTTP302redirect to an internal service:This is mechanically distinct from the DNS-based SSRF explicitly noted as out-of-scope in the
validateRealmURLcomment redirect-based SSRF is fully preventable at the HTTP client layer.Fix
Add
realmRedirectCheck, which applies the same scheme and private-IP restrictions asvalidateRealmURLto every redirect hop. Wire it asCheckRedirecton bothhttp.Clientinstances used for token fetches.Test
TestTokenServerRedirectSSRFspins up a loopback token server that redirects to a second loopback "internal service" and confirms thatbt.refresh()returns an error rather than following the redirect.Relation to prior work
PR #2243 added
validateRealmURLto block direct private-IP realm values. This PR closes the remaining redirect-bypass path that #2243 left open.