Skip to content

Stop forwarding custom auth headers across redirects - #468

Merged
andrew merged 1 commit into
git-pkgs:mainfrom
simonchrz:fix/redirect-auth-header-leak
Oct 14, 2026
Merged

andrew merged 1 commit into
git-pkgs:mainfrom
simonchrz:fix/redirect-auth-header-leak

Conversation

@simonchrz

Copy link
Copy Markdown
Contributor

Handlers set the configured upstream auth header on the outgoing request before handing it to the HTTP client. When an upstream redirects to another host, Go's client copies every header to the next hop except Authorization, WWW-Authenticate and Cookie. A type: header credential (for example X-JFrog-Art-Api) therefore reached the redirect target.

The auth transport (internal/httpclient/transport.go) already applies credentials per hop, scoped to that hop's URL, so the handler-side copy was redundant.

Changes

  • Remove Proxy.applyUpstreamAuth and Proxy.AuthForURL. Auth now comes only from the transport, which every Proxy.HTTPClient and the artifact fetcher go through (server.go).
  • Handler tests that set AuthForURL get their auth through the transport, the same way the server wires it.

Bearer and basic auth were not affected, because Go strips Authorization on cross-host redirects.

Testing

  • New internal/server/upstream_auth_redirect_test.go: a real server with type: header auth scoped to upstream A, and A redirects to host B. Before the fix it failed with redirect target received X-Api-Key = "registry-secret", want none. It now passes, and A still receives the header.
  • go test -race, go vet and golangci-lint v2.13.1 pass.

cmd/proxy mirror never used upstream auth, before or after this change. That is left for a separate change.

Handlers set the configured upstream auth header on the request itself
before handing it to the client. When upstream redirected to another host,
Go's client copied that header to the next hop: it strips only
Authorization and Cookie, so a "header" type credential such as
X-JFrog-Art-Api reached the redirect target. The auth transport already
applies credentials per hop, scoped to each hop's URL.

- Remove Proxy.applyUpstreamAuth and Proxy.AuthForURL; auth comes only
  from the transport
- Add a server test that redirects a header-authenticated upstream to
  another host and asserts the header stays with the upstream
- Wire handler tests' auth through the transport, as the server does
@andrew
andrew merged commit f73f6a7 into git-pkgs:main Oct 14, 2026
6 checks passed
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