Skip to content

Fix auth token leak on cross-host API client redirects#1305

Open
mscoutermarsh wants to merge 1 commit into
mainfrom
cursor/client-redirect-auth-leak-9803
Open

Fix auth token leak on cross-host API client redirects#1305
mscoutermarsh wants to merge 1 commit into
mainfrom
cursor/client-redirect-auth-leak-9803

Conversation

@mscoutermarsh

Copy link
Copy Markdown
Member

Summary

The shared internal/planetscale HTTP client had no CheckRedirect policy, so Go followed redirects while oauth2.Transport / serviceTokenTransport re-attached Authorization on every hop. Unlike headers set on Request.Header, RoundTripper-injected credentials are not stripped on cross-host redirects, so a 3xx Location to another host could leak access or service tokens.

pscale api and query-pattern downloads already guarded this; the core client used by every other service method did not.

Fix

  • Install makeSameHostCheckRedirect on the shared client after options are applied (covers access-token and service-token transports).
  • Compare the exact configured API hostname (case-insensitive). Sibling subdomains are treated as different hosts.
  • Return http.ErrUseLastResponse so the credential-bearing client stops before RoundTrip runs for the foreign host.

Tests

  • Unit cases for same host, port differences, case folding, sibling subdomains, and foreign domains.
  • Integration cases proving access and service tokens are not sent on cross-host redirects (127.0.0.1localhost).
  • Same-host redirects still follow and keep credentials.
Open in Web Open in Cursor 

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
mscoutermarsh marked this pull request as ready for review July 22, 2026 22:34
@mscoutermarsh
mscoutermarsh requested a review from a team as a code owner July 22, 2026 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants