41: `main_checkfds()` pipe reuse leaks proxy credentials into HTTPS upload body
When curl starts with stdin and stderr closed, its descriptor-repair routine can assign opposite ends of one pipe to fd 0 and fd 2. In verbose mode with a stdin-based upload through an authenticated proxy, the proxy credential written to stderr becomes readable as stdin and is sent to the HTTPS origin as upload body data.
Originally disclosed on HackerOne
- Disclosed after 4 days
Summary
When curl is launched with stdin (fd 0) and stderr (fd 2) closed, main_checkfds() in src/tool_main.c can assign opposite ends of the same pipe to fd 0 and fd 2. In verbose mode with a stdin-based upload through an authenticated proxy, the Proxy-Authorization header written to stderr becomes readable from stdin and is sent as upload body data to the HTTPS origin server.
Affected version
curl CLI 7.12.3 through 8.21.0, plus tested 8.22.0 prerelease/development versions on applicable POSIX systems.
Root cause
main_checkfds() (lines 87–95 of src/tool_main.c) loops pipe() until fds 0, 1, and 2 are all open. If fd 0 and fd 2 are both closed while fd 1 is open, the first pipe() call allocates its read end as fd 0 and its write end as fd 2 — opposite ends of the same pipe.
tool_init_stderr() runs before main_checkfds() (line 148 vs 169), binding tool_stderr to the C stderr stream backed by fd 2. In verbose mode, curl writes the outgoing CONNECT request — including Proxy-Authorization — to tool_stderr → fd 2 → pipe write end. An upload from --upload-file . or --upload-file - reads from per->infd = STDIN_FILENO (fd 0) → pipe read end. The proxy credential thus crosses into the upload body sent to the HTTPS origin.
Reproduction
- Build an affected curl command-line tool on a POSIX platform that provides
pipe()andfcntl(). - Start an HTTP
CONNECTproxy that requires Basic authentication, records the incoming proxy request, and tunnels accepted connections to a separate HTTPS origin. - Start the HTTPS origin with a test certificate and have it record the complete decrypted upload request, including the request body.
- Prepare a launcher that keeps stdout open but closes file descriptors 0 and 2 immediately before executing curl.
- Invoke curl through the authenticated proxy with verbose diagnostics enabled and configure an upload whose source is stdin, using either
--upload-file -or the nonblocking stdin form--upload-file .. - Direct the upload to the distinct HTTPS origin and allow the test certificate as appropriate for the isolated environment.
- Confirm that the proxy receives the expected
Proxy-Authorizationheader during theCONNECTrequest. - Inspect the origin's decrypted request and locate the boundary between its HTTP headers and upload body.
- Observe the vulnerable result: the upload body contains verbose diagnostic text, including the proxy's
Proxy-Authorizationheader, even though the origin is not authorized to receive that credential. - Confirm the descriptor arrangement in the launched process: repaired fd 0 is the read end and repaired fd 2 is the write end of the same pipe.
- Repeat the request while leaving stdin open. Confirm that the origin no longer receives the proxy credential in the body.
- Repeat while leaving stderr open. Confirm that the credential is not inserted into the upload.
- Repeat with verbose mode disabled. Confirm that no credential-bearing diagnostic text enters the upload.
- Repeat with verbose diagnostics redirected using
--stderrto a dedicated file. Confirm that the origin does not receive the credential. - Confirm a fix by independently attaching each missing standard descriptor to
/dev/null, for example withopen()anddup2(), instead of retaining connected pipe endpoints. - Repeat the original closed-stdin-and-stderr case and verify that proxy authentication still reaches the proxy but no diagnostic bytes or credentials appear in the HTTPS upload body.
Expected result
Repaired standard descriptors must be independent. Data written to stderr must never become readable as stdin or be incorporated into an upload.
Vulnerable result
When stdin and stderr are both closed, curl can retain opposite ends of one pipe as descriptors 0 and 2. Verbose proxy diagnostics written to stderr are then read as stdin and transmitted to the origin as upload data.
Impact
The proxy credential crosses a principal boundary: the proxy is authorized to receive it, the HTTPS origin is not. TLS does not prevent the disclosure because curl injects the credential into plaintext upload data before encryption.
Practical severity is limited — exploitation requires an unusual local launch configuration (closed fd 0 + fd 2, verbose mode, stdin upload, authenticated proxy, distinct origin). A remote origin cannot independently establish these prerequisites.
Suggested fix
Replace the pipe() loop in main_checkfds() with open("/dev/null", O_RDWR) and dup2() for each missing standard descriptor. This ensures repaired fds are independent sinks/sources rather than connected pipe endpoints.
Impact
Summary:
Under the required closed-descriptor launch configuration, an HTTPS origin can receive credentials intended only for an authenticated proxy because curl inserts verbose diagnostic output into the upload body. This directly discloses reusable proxy credentials to another principal, although a remote origin generally cannot create the unusual local descriptor and command-line prerequisites by itself.
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 descriptor-repair loop in main_checkfds() creates a pipe whose read and write ends land on fd 0 and fd 2, so stderr output becomes readable stdin.
Impact
The HTTPS origin, which is not authorised to receive the proxy credential, could obtain it from the upload body; practical severity is limited because the unusual local launch configuration is required and a remote origin cannot establish it alone.
What the attacker needed
Local launch with fd 0 and fd 2 closed; verbose mode enabled; upload sourced from stdin; authenticated HTTP proxy
The fix
The descriptor-repair loop should attach each missing standard descriptor independently to /dev/null using open() and dup2() instead of keeping connected pipe endpoints.
How it was found
- Build an affected curl command-line tool on a POSIX platform.
- Start an HTTP CONNECT proxy requiring Basic authentication and an HTTPS origin that records uploads.
- Launch curl with stdout open but file descriptors 0 and 2 closed.
- Run curl through the proxy in verbose mode with an upload sourced from stdin.
- Inspect the origin's decrypted request and find the proxy credential in the upload body.
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.
A program uses numbered slots called file descriptors for input, output and errors. If two of those slots are closed at launch, curl fills them by creating a pipe, and here it accidentally put the two ends of the same pipe into the input and error slots. So text curl wrote as an error message, including a proxy password, could be read back as if the user had typed it and uploaded to the website.
What is Info disclosure?
Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.