Attach GitHub token only to configured GitHub hosts - #3056
Open
SyedAnas01 wants to merge 1 commit into
Open
Conversation
De-ASI-INTERFACE
approved these changes
Aug 13, 2026
De-ASI-INTERFACE
approved these changes
Aug 13, 2026
BearerAuthTransport re-adds the Authorization header on every hop, which defeats net/http's cross-host redirect stripping. Scope the credential to the configured hosts so a redirect off them travels without the token. An empty AllowedHosts preserves prior behavior; the three production construction sites populate it from the configured REST, upload, GraphQL and raw hosts.
SyedAnas01
force-pushed
the
host-scoped-token
branch
from
August 13, 2026 02:32
d71fd03 to
11f062c
Compare
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.
BearerAuthTransportsets theAuthorizationheader on every request it processes. Go'snet/httpstrips theAuthorizationheader when a redirect crosses to a different host, but that only covers headers set on the initial request. Because this transport re-adds the header on every hop, a redirect that leaves the configured GitHub hosts would carry the token to the redirect target.Today that is not reachable with an attacker-controlled destination, because GitHub's cross-host redirects (release assets, archives) resolve to GitHub-owned hosts such as
objects.githubusercontent.comandcodeload.github.com. This change stops the transport from relying on that invariant: it attaches the token only when the request host is one of the configured GitHub hosts (REST, GraphQL, upload, raw), so any redirect off them travels without the credential.A
CheckRedirectthat stripsAuthorizationdoes not work here, because the header is re-added by the transport on the next hop. The credential decision has to live in the transport, at the point where the header is set. An emptyAllowedHostspreserves the prior behavior, so this is backward compatible; the three production construction sites populate it from the configured hosts.Tests cover the token being sent to allowed hosts, withheld from a non-allowed redirect target and from arbitrary hosts, and the empty-
AllowedHostsdefault. This is a hardening change, not a response to a known exploit.