CVE-2026-111951: curl -OJ truncate without filename
When curl is run with -O -J, a Content-Disposition header that has no usable filename causes curl to open and truncate the URL-derived file before a later header naming an existing file is refused. A malicious or compromised server can therefore wipe an existing local file to zero bytes while curl reports that it refused to overwrite it.
- Triaged in 24 hours
- Fixed in 8 days
- Disclosed after 8 days
Summary:
With -O -J, when a response carries a Content-Disposition header without a usable filename= (for example inline) before the one that names an existing file, curl truncates that existing file to 0 bytes and then exits 23 saying it refused to overwrite it. This breaks the promise in docs/cmdline-opts/remote-header-name.md: "If the server specifies a filename and a file with that name already exists in the destination directory, it is not overwritten and an error occurs".
The cause is src/tool_cb_hdr.c lines 405 to 408 in curl-8_23_0: when the header has no filename=, the code falls through to tool_create_output_file(), which opens the URL-derived name with fopen(fname, "wb") (src/tool_cb_wrt.c line 87) because is_cd_filename is still FALSE. The following filename="victim" header is then refused by set_filename() since the stream is already open, but the file is already empty. The same happens with -L when a 302 carries Content-Disposition: inline before Location:, with filename*= first, and over HTTPS; with -i the file gets the response headers written into it.
AI assistance was used for testing and code review; the writing and findings are mine.
Affected version
curl 8.23.0 (also 8.22.0 and master 70f3f855c6), macOS, OpenSSL 3.6.5 build. Only the curl tool.
Steps To Reproduce:
- Run any HTTP server on 127.0.0.1:32700 that answers:
HTTP/1.1 200 OK
Content-Disposition: inline
Content-Disposition: attachment; filename="victim"
Content-Length: 8
PAYLOAD
- Run:
printf 'ORIGINAL-CONTENT\n' > victim
curl -sS -OJ http://127.0.0.1:32700/victim; echo "exit=$?"; wc -c victim
- Result:
curl: (23) client returned ERROR on write of 52 bytes
exit=23
0 victim
Control: with only Content-Disposition: attachment; filename="victim" curl exits 23 and victim stays 17 bytes.
Proposed fix:
--- a/src/tool_cb_hdr.c
+++ b/src/tool_cb_hdr.c
@@ -405,8 +405,12 @@ static size_t content_disposition(const char *str, const char *end,
}
break;
}
- if(!outs->stream && !tool_create_output_file(outs, per->config))
- return CURL_WRITEFUNC_ERROR;
+ if(!outs->stream) {
+ if(hdrcbdata->config->show_headers)
+ return buffer_header(hdrcbdata, str, cb);
+ return cb;
+ }
if(tool_write_headers(&per->hdrcbdata, outs->stream))
return CURL_WRITEFUNC_ERROR;
buffer_header() needs a forward declaration above content_disposition(). With this patch every case above leaves the file intact, and a Content-Disposition with no filename at all still falls back to the URL name.
Impact
Summary:
A user running curl -OJ https://host/report.pdf (or with -L) in a directory that already holds report.pdf gets that file truncated to 0 bytes by a malicious or compromised server, while curl reports that it refused to overwrite it.
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 when a Content-Disposition header lacks a filename, the header callback falls through to creating the output file from the URL name, so the file is opened and truncated before a later filename-bearing header is rejected.
Impact
A malicious or compromised server could truncate an existing local file to zero bytes while curl reports that it refused to overwrite it; the same happens with -L, with filename* first, and over HTTPS.
What the attacker needed
Curl tool with -O -J; victim runs curl against hostile server; a file with the target name already exists
The fix
The report proposes a patch that buffers the header instead of creating the output file when no filename is present, leaving the file intact and still falling back to the URL name when no filename is given at all.
How it was found
- Run a local HTTP server that sends a Content-Disposition header without a filename, then one naming an existing file.
- Create a file with that name containing some content.
- Run curl with -O -J against the server and check the exit code and file size.
- Observe that curl exits with code 23 and the file is now 0 bytes.
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 downloading things. The -O option saves a download under its URL name, and -J lets the server suggest the name instead. The bug is that curl creates and empties the file too early, so a server can make it destroy a file you already had, even though curl then says it would not overwrite it.
What is File upload?
An upload feature accepts a file that the server or other users' browsers then treat as code or as something trusted.