Skip to content

fix(proxy): send proxy headers on every redirect hop - #3149

Open
leoleducq wants to merge 1 commit into
seanmonstar:masterfrom
leoleducq:fix-proxy-auth-on-redirect
Open

leoleducq wants to merge 1 commit into
seanmonstar:masterfrom
leoleducq:fix-proxy-auth-on-redirect

Conversation

@leoleducq

@leoleducq leoleducq commented Nov 20, 2026 •

Copy link
Copy Markdown

Left unchecked on purpose: the description and the comment in the diff were drafted with an AI assistant. The fix and the regression test were checked by running them (the test fails on master and passes here). Happy to rewrite anything in my own words if you prefer.

Fixes #2177.

Problem

Through an HTTP proxy that requires basic auth (Proxy::http("http://user:pass@proxy"), HTTP_PROXY, ...), a redirect to an http:// URL on another host gets 407 Proxy Authentication Required:

  • http://a/ redirects to http://b/: the second request reaches the proxy without Proxy-Authorization.
  • https://a/ redirects to http://b/: the first hop authenticates in the CONNECT tunnel, the http hop is sent without Proxy-Authorization.

Requesting the final URL directly works.

execute_request adds the proxy headers (proxy_auth, proxy_custom_headers) to the first request only. On a cross-origin redirect, remove_sensitive_headers strips Proxy-Authorization, and nothing computes it again for the next hop.

Stripping it is right for a header the caller set by hand, as discussed in #2177. This change keeps that. The credentials configured on the proxy are different: they belong to the proxy, and should go with every request sent to it, as on the first request. curl (--proxy-user) and Go's net/http (credentials in the proxy URL) send them on every request that goes through the proxy, redirects included.

Fix

Move proxy_auth and proxy_custom_headers from Client::execute_request into HyperService::call. HyperService sits below FollowRedirect, like CookieService, so each hop gets the headers of the proxy that intercepts its own URI. The rules don't change: http destinations only, the first matching proxy only, and a Proxy-Authorization already on the request is kept.

Test

http_proxy_basic_auth_on_cross_host_redirect in tests/proxy.rs: the test server acts as the proxy, answers 407 when Proxy-Authorization is missing, and redirects http://hyper.rs.local/redirect to http://other.rs.local/dst. It fails on master (407) and passes with this change. cargo fmt --check and cargo test (default features, and cookies,blocking,gzip,stream,socks) pass.

Proxy-Authorization and proxy custom headers were only added to the
first request in `execute_request`. On a cross-origin redirect,
`remove_sensitive_headers` strips Proxy-Authorization and nothing put
it back, so an http hop through an authenticated proxy got a 407.

Apply the proxy headers in `HyperService`, below the redirect layer, so
each hop gets the headers of the proxy that intercepts its own URI.

Closes seanmonstar#2177
@leoleducq
leoleducq marked this pull request as draft November 20, 2026 08:14
@leoleducq
leoleducq marked this pull request as ready for review November 20, 2026 09:04
@seanmonstar

Copy link
Copy Markdown
Owner

Left unchecked on purpose: the description and the comment in the diff were drafted with an AI assistant. The fix and the regression test were checked by running them (the test fails on master and passes here). Happy to rewrite anything in my own words if you prefer.

☹️ Um, yes, that is the preference, that's why I ask people to communicate in their own words. Consider.

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.

Redirects fails proxy authentification

2 participants