Repository navigation
credentials/sts: do not follow redirects during token exchange - #9299
Merged
Merged
Conversation
The token exchange POST carries the subject token in its body, so following a redirect replays that secret to the redirect target. net/http populates GetBody for the bytes.Buffer body, so a 307/308 resends it, and only Authorization/Cookie headers are stripped on redirect, not the body. Refuse redirects so the token is never sent to an unintended host.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9299 +/- ##
==========================================
- Coverage 83.11% 83.07% -0.05%
==========================================
Files 423 423
Lines 35231 35258 +27
==========================================
+ Hits 29284 29292 +8
- Misses 4432 4446 +14
- Partials 1515 1520 +5
🚀 New features to boost your workflow:
|
easwars
approved these changes
Aug 10, 2026
| } | ||
| select { | ||
| case body := <-leaked: | ||
| t.Errorf("redirect target received request body %q; the subject token must not be replayed to another host", body) |
Contributor
|
/gemini review |
Contributor
There was a problem hiding this comment.
Code Review
This pull request configures the STS HTTP client to refuse to follow redirects, preventing the potential replay of sensitive token exchange request bodies to redirect targets. A new unit test, TestSendRequestDoesNotFollowRedirects, has been added to verify this behavior. I have no further feedback to provide.
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.
The token exchange request in credentials/sts sends the subject token (and an optional actor token) in the POST body, but makeHTTPClient sets no CheckRedirect, so the client follows redirects with the default policy. constructRequest hands the body to http.NewRequestWithContext as a bytes.Buffer, which makes net/http set Request.GetBody, so a 307 or 308 reply from the token endpoint replays the body to the redirect target, and a cross-host redirect only drops the Authorization and Cookie headers, not the body. A malicious or compromised token endpoint, or a MITM since validateOptions still allows a plaintext http URI, can aim that redirect at any host and collect the subject token.
Set CheckRedirect on the client so redirects are never followed. sendRequest already turns any non-2xx into an error, so a 3xx now fails the exchange cleanly instead of resending the credential. Putting the policy on the client the package builds keeps every caller covered without adding a redirect knob to Options. Added a test that redirects the exchange to a second server and checks it never receives the body.
RELEASE NOTES: