Skip to content

Keep configured HTTP headers on the repository origin across redirects - #957

Merged
slachiewicz merged 1 commit into
apache:masterfrom
slachiewicz:http-headers-origin-scoped
Sep 3, 2026
Merged

Keep configured HTTP headers on the repository origin across redirects#957
slachiewicz merged 1 commit into
apache:masterfrom
slachiewicz:http-headers-origin-scoped

Conversation

@slachiewicz

Copy link
Copy Markdown
Member

Fixes #956.

Headers configured for a repository (setHttpHeaders, <httpConfiguration> method headers) were set on every request, and HttpClient's redirect handling copied them onto the redirected request, so a repository that redirected to another host received them there too. Those headers are often credentials.

AbstractHttpClientWagon now puts the repository origin and the configured header names into the per-request HttpClientContext, and a request interceptor registered once on the shared client, OriginScopedHeadersInterceptor, removes those headers from any request whose target host differs from the origin in scheme, host or effective port. A redirect within the same origin keeps them. User-Agent is exempt, since it identifies the client rather than the repository. Basic authentication through the credentials provider is unchanged; HttpClient already scopes it by host.

-Dmaven.wagon.http.originScopedHeaders=false restores the previous behaviour.

Two tests in HttpWagonTestCase cover a redirect to another origin (header must not arrive) and a redirect within the origin (header must arrive). wagon-http-lightweight follows redirects inside HttpURLConnection and cannot apply the same rule; its test class opts out of the two tests and the gap remains documented in #956.

Verified: mvn -pl wagon-providers/wagon-http-shared,wagon-provider-test,wagon-providers/wagon-http -am verify → green, 60 tests in HttpWagonTest.

This change was created with AI assistance.

Fixes apache#956. HttpClient copies the headers of the original request onto
every redirected request, so headers configured for a repository through
setHttpHeaders or the method configuration followed redirects to other
hosts. The wagon now records the repository origin and the configured
header names in the request context, and an interceptor on the shared
client removes those headers from any request whose target differs from
the origin in scheme, host or effective port. User-Agent is exempt.
Setting -Dmaven.wagon.http.originScopedHeaders=false restores the
previous behaviour.
@slachiewicz slachiewicz added the bug Something isn't working label Sep 2, 2026
@slachiewicz
slachiewicz merged commit 5111b31 into apache:master Sep 3, 2026
8 checks passed
@github-actions github-actions Bot added this to the 4.0.0-M1 milestone Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Configured HTTP headers are sent to other hosts when a repository redirects

1 participant