Skip to content

credentials/sts: do not follow redirects during token exchange - #9299

Merged
mbissa merged 2 commits into
grpc:masterfrom
nvxbug:sts-token-redirect
Aug 11, 2026
Merged

mbissa merged 2 commits into
grpc:masterfrom
nvxbug:sts-token-redirect

Conversation

@nvxbug

@nvxbug nvxbug commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • credentials/sts: Disallow HTTP redirects in the credentials implementation, to prevent leaking tokens

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

codecov Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.07%. Comparing base (1ecbd86) to head (c9650af).
⚠️ Report is 2 commits behind head on master.

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     
Files with missing lines Coverage Δ
credentials/sts/sts.go 92.66% <100.00%> (-0.20%) ⬇️

... and 33 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread credentials/sts/sts_test.go Outdated
}
select {
case body := <-leaked:
t.Errorf("redirect target received request body %q; the subject token must not be replayed to another host", body)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: s/redirect/Redirect

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, capitalized.

@easwars
easwars requested a review from mbissa August 10, 2026 18:55
@easwars easwars added Type: Security A bug or other problem affecting security Area: Auth Includes regular credentials API and implementation. Also includes advancedtls, authz, rbac etc. labels Aug 10, 2026
@easwars easwars added this to the 1.84 Release milestone Aug 10, 2026
@mbissa

mbissa commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mbissa mbissa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mbissa
mbissa merged commit 0c51461 into grpc:master Aug 11, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Auth Includes regular credentials API and implementation. Also includes advancedtls, authz, rbac etc. Type: Security A bug or other problem affecting security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants