fix(http): skip AuthTransport bearer on redirected hops#832
Open
SAY-5 wants to merge 1 commit into
Open
Conversation
AuthTransport.RoundTrip unconditionally re-set the Authorization header, which clobbered stdlib http.Client's cross-host strip on artifact-download redirects to presigned buildkiteartifacts.com / S3 URLs. The presigned URL already carries its own auth via X-Amz-Signature, so the extra header either leaks the bearer or breaks the download with S3's 'Only one auth mechanism allowed' 400. Closes buildkite#830 Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
mcncl
reviewed
May 19, 2026
| token := t.TokenSource.Token() | ||
| if token != "" { | ||
| req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token)) | ||
| // Skip re-injecting on redirected hops so stdlib's cross-host strip stays in effect. |
Contributor
There was a problem hiding this comment.
@SAY-5 thanks for the PR! As far as I can tell, this only fixes the normal redirect hop, which is fine (and a nice fix). I'm wondering if you wanted to additionally include a fix for 401 responses, which will still use the RefreshTransport
Author
There was a problem hiding this comment.
Good catch. The 401-retry path is a separate failure mode (refresh + cloned request, where req.Response is nil) so I would rather address it in a follow-up PR with its own test, to keep this one tightly scoped to the redirect leak. I will open that next.
Contributor
There was a problem hiding this comment.
CI is failing due to an expired token, I think, so I'll look in to fixing that up
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.
AuthTransport.RoundTripunconditionally re-set the Authorization header, which clobbered stdlibhttp.Client's cross-host strip on artifact-download redirects to presignedbuildkiteartifacts.com/ S3 URLs. The presigned URL already carries its own auth viaX-Amz-Signature, so the extra header either leaks the bearer or breaks the download with S3's "Only one auth mechanism allowed" 400. New test redirects through twohttptestservers and asserts the second hop sees noAuthorization.Closes #830