Fix auth token leak on cross-host API client redirects#1305
Open
mscoutermarsh wants to merge 1 commit into
Open
Fix auth token leak on cross-host API client redirects#1305mscoutermarsh wants to merge 1 commit into
mscoutermarsh wants to merge 1 commit into
Conversation
The shared planetscale Client followed redirects with no CheckRedirect policy. oauth2.Transport and serviceTokenTransport re-attach Authorization on every hop, and net/http does not strip RoundTripper-injected headers on cross-host redirects, so a 3xx Location to another host leaked access or service tokens. Install the same exact-host redirect guard already used by pscale api so credentials only follow redirects to the configured API hostname. Co-authored-by: Mike Coutermarsh <coutermarsh.mike@gmail.com>
mscoutermarsh
marked this pull request as ready for review
July 22, 2026 22:34
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
The shared
internal/planetscaleHTTP client had noCheckRedirectpolicy, so Go followed redirects whileoauth2.Transport/serviceTokenTransportre-attachedAuthorizationon every hop. Unlike headers set onRequest.Header, RoundTripper-injected credentials are not stripped on cross-host redirects, so a3xxLocationto another host could leak access or service tokens.pscale apiand query-pattern downloads already guarded this; the core client used by every other service method did not.Fix
makeSameHostCheckRedirecton the shared client after options are applied (covers access-token and service-token transports).http.ErrUseLastResponseso the credential-bearing client stops beforeRoundTripruns for the foreign host.Tests
127.0.0.1→localhost).