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.
4 tasks
Subserial
requested changes
May 12, 2026
Subserial
left a comment
Contributor
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
Contributor
|
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
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.