Skip to content
Crypto Disclosed report Advanced

43: HTTP proxy CONNECT header chooses the `-OJ` filename after a redirect

A stale HTTP response code from a redirect causes curl to treat a proxy's CONNECT response Content-Disposition header as if it came from the TLS-verified origin, letting the proxy choose the local output filename. An attacker controlling the proxy can thus control the name under which curl saves an authenticated origin's response body.

giant_anteater Follow

Originally disclosed on HackerOne

  • Disclosed after 12 days

Summary

When curl follows an HTTPS redirect through an HTTP CONNECT proxy, a stale response code lets the proxy's CONNECT response Content-Disposition header control the local output filename. With --location --remote-name --remote-header-name, the proxy-provided filename is used for the TLS-verified origin's response body, crossing the CONNECT/origin trust boundary.

Root cause

Curl_req_soft_reset() in lib/request.c does not clear data->info.httpcode. After the first origin's 302 response, this stale value persists while curl establishes a new CONNECT tunnel for the redirect target.

single_header() in lib/cf-h1-proxy.c delivers CONNECT response headers to the header callback with CLIENTWRITE_CONNECT, but this provenance bit is internal to the writer chain — it never reaches CURLOPT_HEADERFUNCTION. The stale httpcode is only cleared when the tunnel reaches H1_TUNNEL_ESTABLISHED, after headers have already been delivered.

tool_header_cb() in src/tool_cb_hdr.c calls CURLINFO_RESPONSE_CODE, sees the stale 302, and passes the proxy's Content-Disposition header to content_disposition(), which opens the output file under the proxy-chosen name and disables further filename handling. The real origin's Content-Disposition header arrives later but is ignored.

Steps to reproduce

The PoC uses two certificate-verified HTTPS origins and an HTTP/1.1 CONNECT proxy, all on loopback. Origin 1 returns a 302 redirect to Origin 2. The proxy injects Content-Disposition: attachment; filename="proxy-chosen.bin" in the CONNECT response for Origin 2. Origin 2 returns Content-Disposition: attachment; filename="origin-name.bin" with a body.

Expected vs actual output

Expected: All three cases produce origin-name.bin — the filename from the TLS-verified origin.

Actual: The redirect case produces proxy-chosen.bin containing the authenticated origin's body. The two controls correctly produce origin-name.bin. This shows the proxy's CONNECT response header overwrites the filename only when a stale 3xx code is present from a prior redirect.

Suggested fix

Prevent CONNECT-provenance headers from participating in --remote-header-name processing. The strongest fix would propagate header provenance to the command-line callback so it can distinguish CONNECT headers from origin headers. Alternatively, clearing data->info.httpcode before CONNECT headers are delivered (rather than after, in H1_TUNNEL_ESTABLISHED) would close this specific trigger.

Impact

A malicious HTTP proxy (or an on-path attacker against the plaintext proxy hop) can choose the local basename for data returned by an authenticated HTTPS origin. The attacker cannot modify the TLS-protected response body, but controls the name under which curl stores it.

The filename is subject to curl's basename sanitization. Existing files are preserved by default; --clobber permits replacement. Using --suppress-connect-headers mitigates the issue.

The original report as published on HackerOne, by giant_anteater. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the stale HTTP response code from the first origin's redirect is not cleared before the proxy's CONNECT response headers are processed, so the command-line header callback treats those proxy headers as origin headers.

Impact

A malicious proxy or on-path attacker against the plaintext proxy hop can choose the local basename for data from an authenticated HTTPS origin, though the body itself cannot be modified and the filename is subject to basename sanitisation; --suppress-connect-headers mitigates the issue.

What the attacker needed

Curl with --location --remote-name --remote-header-name; a malicious or on-path HTTP proxy; an HTTPS origin that redirects

The fix

The fix should prevent CONNECT-provenance headers from participating in --remote-header-name processing, for example by propagating header provenance to the command-line callback or by clearing the stale response code before CONNECT headers are delivered.

How it was found

  1. Set up two certificate-verified HTTPS origins and an HTTP/1.1 CONNECT proxy on loopback.
  2. Make Origin 1 return a 302 redirect to Origin 2.
  3. Have the proxy inject a Content-Disposition header in the CONNECT response for Origin 2.
  4. Have Origin 2 return its own Content-Disposition header and a body.
  5. Run curl with --location --remote-name --remote-header-name and observe the saved filename.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When curl downloads a file, it can use a header from the server to decide the file's name. Here, after a redirect, curl mistakenly trusts a header from the proxy (the middleman) instead of the real website, so the middleman can pick the filename. The file contents still come from the real site, but the name is chosen by the attacker.

What is Crypto?

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.

More by giant_anteater

View all

93 more disclosed reports, best first.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cryptographic weaknesses

The lesson behind this report.

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.