-H with space prefix leads to previous header injection when used with --proxy
When curl is used with a proxy, a header argument that begins with a space is appended to the previous header line instead of being sent as its own header. An attacker who can influence a header value or a header file could therefore inject or alter headers in requests sent through the proxy.
Originally disclosed on HackerOne
- Disclosed after 7 months
Summary:
Hi team, I hope you're doing well.
Recently I came accross this weird curl behavior where -H "[space]header: value" would inject the header in the previous HTTP header.
Tried it on mac OS Sequoia 15.1 with curl version
curl 8.11.0 (aarch64-apple-darwin24.1.0) libcurl/8.11.0 OpenSSL/3.4.0 (SecureTransport) zlib/1.2.12 brotli/1.1.0 zstd/1.5.6 AppleIDN libssh2/1.11.1 nghttp2/1.64.0 librtmp/2.3
Release-Date: 2024-11-06
Weirdly, this only seems to work when --proxy argument exists.
Steps To Reproduce:
curl -X GET "https://iaw2x2g8gw7mfnouqxj3z2hc036uunic.oastify.com" -H "Secure-Header: XYZ" -H " new-header-that-will-inject-to-previous-header: value" --proxy 127.0.0.1:8080
Resulting request:

when the first header itself contains space, the behavior will again be to attach to previous header:
curl -X GET "https://iaw2x2g8gw7mfnouqxj3z2hc036uunic.oastify.com" -H " new-header-that-will-inject-to-previous-header: value" --proxy 127.0.0.1:8080

Without proxy argument however, the behavior is normal and it will send them in new lines:
curl -X GET "https://iaw2x2g8gw7mfnouqxj3z2hc036uunic.oastify.com" -H " new-header-that-will-inject-to-previous-header: value"
Resulting request:

This also works with -H @file.txt where the file begins with the space.
I do not have an exact scenerio where this can be exploited, however, since curl is so widely used, I can imagine a scenerio where @file.txt or a single header name input may be attacker controlled in someway, which can lead to malformed requests to servers.
Also, if request like this is sent:
curl -X GET "https://iaw2x2g8gw7mfnouqxj3z2hc036uunic.oastify.com" -H " new-header-that-will-inject-to-previous-header: value" -H @headers2.txt -H 'User-Agent:' -H 'Accept:' --proxy 127.0.0.1:8080
The headers will directly attach to Host header, which may lead to incorrect logging, and introduce other issues depending upon the program.

Since, headers field-name can't contain spaces anyway, stripping them and always adding them to new line would be prefect solution.
Impact
Previous header/ previous line injection via -H
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 curl's proxy request-building path does not strip leading whitespace from header names, so a space-prefixed header is treated as a continuation of the previous header line.
Impact
The reporter did not demonstrate a concrete exploit, but notes that attacker-controlled header input or header files could produce malformed requests, and that headers may attach to the Host header, which may lead to incorrect logging and other issues.
What the attacker needed
Curl used with a proxy; header input starts with a space; attacker can influence header input
How it was found
- Run curl with a proxy and pass a header whose name starts with a space.
- Observe the request the proxy receives.
- Repeat without the proxy argument and compare the request.
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.
curl is a command-line tool for sending web requests. A header is a small labelled line of extra information sent with a request. The reporter found that if a header name starts with a space and a proxy is in use, curl glues that header onto the end of the previous one instead of starting a new line, so the request is built differently from what the user intended.
What is Smuggling / CRLF?
A front end and a back end split one connection's bytes into requests differently, letting an attacker hide a request inside another user's.