Skip to content

cmd/go: do not forward GOAUTH-derived credential headers across cross-host redirects #77839

Description

@1seal

summary:

  • when cmd/go uses GOAUTH, it may add arbitrary custom headers (not just Authorization) to authenticate to a specific https:// URL prefix.
  • net/http copies request headers across redirect hops, and cmd/go currently preserves those copied headers.
  • if a request authenticates to host a and then redirects to a different host b, those GOAUTH-derived headers can be forwarded to b.

expected behavior:

  • when following a redirect to a different host, cmd/go should not forward GOAUTH-derived credential headers from the original host.
  • credentials should only be applied when they are derived for (or match) the destination URL prefix.

actual behavior:

  • after GOAUTH is applied (triggered by a prior 4xx), a subsequent 3xx redirect to a different host can result in the GOAUTH-derived header being sent to the redirect target host.

notes:

  • i understand from the private security triage discussion that this is not considered a security vulnerability. i am filing this as a behavior change / hardening request for cmd/go’s GOAUTH scoping model.
  • redirect preconditions are: unauthenticated 4xx (to trigger GOAUTH), then authenticated 3xx (redirect), then a redirect target on a different host.

repro sketch:

  1. configure GOAUTH to return a custom header for https://a.test/ (example: X-Goauth-Token: secret).
  2. make a request to https://a.test/ such that:
    • the first response is 401,
    • the second request includes the GOAUTH header,
    • the second response is a 302 redirect to https://b.test/.
  3. observe that the request to https://b.test/ contains X-Goauth-Token.

proposed fix:

  • in cmd/go’s redirect handler, clear the copied header set on redirected requests and re-derive credentials based on the destination URL only.
  • add a regression test that proves a custom GOAUTH header is applied to a.test but not forwarded to b.test.

callsite (observed):

  • a3688ab
  • src/cmd/go/internal/web/http.go (redirect policy)

patch + test:

Metadata

Metadata

Assignees

No one assigned

    Labels

    GoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolProposalIssues describing a requested change to a Go tool or command-line program.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions