[node-downloader-helper] Path traversal via Content-Disposition header
The node-downloader-helper library did not sanitise the filename taken from a server's Content-Disposition header, so a malicious server could use ../ sequences to write the downloaded file outside the intended directory. The reporter claims this could lead to remote code execution by placing an executable in a Windows startup folder or an authorised_keys file on Linux.
- Triaged in 10 hours
- Fixed in 9 months
- Disclosed after 10 months
Summary
I would like to report path traversal in node-downloader-helper.
It allows malicious server to choose download location via ../. It may leads remote code execution.
Module
module name: node-downloader-helper
version: 1.0.11
npm page: https://www.npmjs.com/package/node-downloader-helper
Module Description
A simple http file downloader for node.js
Features:
- No thirdparty dependecies
- Pause/Resume
- Retry on fail
- Supports http/https
- Supports http redirects
- Supports pipes
- Custom native http request options
- Usable on vanilla nodejs, electron, nwjs
- Progress stats
Module Stats
13,911 weekly downloads
Vulnerability
Vulnerability Description
Since there is no sanitization of file path, malicious server is able to traversal path of victim machine. It leads remote code execution by putting malicious executable to startup folder in Windows. (In Linux, it's possible to create authorized_key.).
Steps To Reproduce:
- Put
poc.phpto the server. (or you can use my server's PoC: https://exec.ga/download-test.php ) - Modify
poc.jsto set URL of thepoc.php - Execute
node poc.js evil.txtwill be saved to parent directory of the directory which containspoc.js
Supporting Material/References:
- Windows 10
- v12.13.1
- 6.12.1
Wrap up
- I contacted the maintainer to let them know: N
- I opened an issue in the related repository: N
Impact
Attacker is able to put malicious contents anywhere of victim's machine.
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
Impact
An attacker controlling the download server could write malicious content anywhere the victim's user account can write, which may lead to remote code execution.
What the attacker needed
Victim downloads from an attacker-controlled server; user account can write to target folder
How it was found
- Host a file on a server that returns a crafted Content-Disposition filename.
- Point the downloader script at that server's URL.
- Run the script with node.
- Observe that the downloaded file is written to the parent directory instead of the expected folder.
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, the server can suggest a name for it. This library trusted that suggested name completely, so a name containing '../' could make the file land in a folder above the one you expected. A malicious server could therefore drop a file almost anywhere the user can write, which is dangerous if that location is one the system runs automatically.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.