Skip to content

Core module: Return a redirect whose Location header does not parse as the redirect response itself, so a secret in that header stays out of logs - #243

Merged
QuintinWillison merged 2 commits into
mainfrom
core-redirect-location-stays-out-of-errors
Dec 2, 2026
Merged

QuintinWillison merged 2 commits into
mainfrom
core-redirect-location-stays-out-of-errors

Conversation

@QuintinWillison

Copy link
Copy Markdown
Member

🤖 Claude's Summary

When a redirect's Location header does not parse as a URL, Go's http.Client fails the request with an error whose text quotes the header twice (client.go). The client that Configuration.HTTPClient returns passed that text on. A Location can hold a secret, such as the access token in the redirect that ends a sign-in, so a program that logged the error wrote that secret to its log.

The SDK's transport now removes a Location header that does not parse from a redirect response, of any 3xx status. Go's client returns a redirect that has no Location header as the response itself (Go 1.19 release notes), so the request no longer fails, and a domain client reports the redirect as it reports any other non-2xx response. That is how the SDK has answered a redirect to another origin since #227. A read no longer retries such a redirect.

The other repair would be to rewrite the error. Go gives that error no type of its own, so only its English wording could identify it, and Go does not promise to keep an error's wording: Go 1.14 reworded part of this one. Removing the header depends on no text. The check for a header that does not parse is url.Parse, which is the check Go's client makes.

HTTPClient's doc comment gains the new case beside the two it already lists for a redirect. Its sentence on a failed Do, from #232, now says that the error's URL leaves out the query string and user information. It said that of the error's whole text, which the SDK does not control, since the cause is Go's or the transport's own.

The first commit pins the defect with a test that passes against it. Its second case, a response of another status that carries the same header, keeps the header before the fix and after it. The fix follows and flips the redirect case. No service in the local stack sends a Location that does not parse, so the test uses a local server and has no integration test beside it.

QuintinWillison and others added 2 commits November 30, 2026 12:48
…n header does not parse quotes that header whole, with any secret it holds.

Co-Authored-By: Claude <noreply@anthropic.com>
…rse as a URL, so the configured HTTP client returns the response itself where it failed with an error that quoted the header.

Co-Authored-By: Claude <noreply@anthropic.com>
@QuintinWillison QuintinWillison self-assigned this Nov 30, 2026
@QuintinWillison QuintinWillison added the SR A response to a security review. Improves any facet of this codebase in terms of security stance. label Nov 30, 2026
@QuintinWillison
QuintinWillison marked this pull request as ready for review November 30, 2026 13:03
@QuintinWillison
QuintinWillison removed this pull request from stack #242 December 2, 2026 11:02
Base automatically changed from postgrest-server-counts-writes-to-table-named-rpc to main December 2, 2026 11:03
@QuintinWillison
QuintinWillison merged commit b5ed0b9 into main Dec 2, 2026
12 checks passed
@QuintinWillison
QuintinWillison deleted the core-redirect-location-stays-out-of-errors branch December 2, 2026 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

SR A response to a security review. Improves any facet of this codebase in terms of security stance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant