[simplehttpserver] Stored XSS in file names leads to malicious JavaScript code execution when directory listing is output in HTML
The simplehttpserver module outputs file names directly into HTML without sanitisation, allowing an attacker to embed HTML or JavaScript in a file name. When a victim clicks such a file in the directory listing, malicious JavaScript can execute.
- Triaged in 3 days
- Fixed in 31 days
- Disclosed after 31 days
Hi Guys,
simplehttpserver allows to embed HTML in file names, which (in certain conditions) might lead to execute malicious JavaScript.
Module:
'simpehttpserver' is simple imitiation of python's SimpleHTTPServer and intended for testing, development and debugging purposes
https://www.npmjs.com/package/simpehttpserver
Description
This issue is another example of lack of output sanitization. Here's source code, which allows to embed HTML in file name and run attack presented in PoC section (./node_modules/simplehttpserver/simplehttpserver.js, lines 106-117):
// Check for each file if it's a directory or a file
var q = async.queue(function(item, cb) {
fs.stat(path.join(pathname, item), function(err, stat) {
if ( !stat ) cb();
if ( stat.isDirectory() ) {
ulist.push('<li><a href="'+item+'/">'+item+'/</a></li>')
} else {
ulist.push('<li><a href="'+item+'">'+item+'</a></li>')
}
cb();
});
}, 4);
As you can see, item is output directly into HTML without any sanitization.
PoC - Steps To Reproduce:
In the directory which will be served via simple-server, create file with following name:
javascript:alert('You are pwned!')
Run simplehttpserver in directory with file with changed filename:
$ ./node_modules/simplehttpserver/cli.js
Listening 0.0.0.0:8000 web root dir /Users/bl4de/playground/node_bugbounty_playground
and open http://127.0.0.1:8000 in the browser.
Try to open file with name javascript:alert('You are pwned!') by clicking it.

Supporting Material/References:
Configuration I've used to find this vulnerability:
- macOS HighSierra 10.13.3
- node 8.9.3
- npm 5.5.1
- curl 7.54.0
Wrap up
I hope this report will help to keep Node ecosystem more safe. If you have any questions about any details of this finding, please let me know in comment.
Thank you
Regards,
Rafal 'bl4de' Janicki
Impact:
This vulnerability can be used to eg. download malware via "drive-by-download" attacks. Also, as described in other modules I've reported similar vulnerabilty, an iframe with malicious JS file loaded from external resource can be executed.
Impact
This vulnerability can be used to eg. download malware via "drive-by-download" attacks. Also, as described in other modules where I've reported similar vulnerabilty, an iframe with malicious JS file loaded from external resource can be executed.
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
The server inserts file names into HTML without escaping or sanitising them.
Impact
This could be used to download malware via drive-by-download attacks, and an iframe with malicious JavaScript from an external resource can be executed.
What the attacker needed
Attacker can create a file with a crafted name; victim clicks the file link
How it was found
- Create a file in the served directory with a name containing JavaScript code.
- Start simplehttpserver in that directory.
- Open the server's address in a browser.
- Click the file with the crafted name to trigger the script.
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 simple web server lists files in a folder and shows their names as clickable links. If a file name contains special characters that look like code, the server puts them into the page without cleaning them up. Then clicking the link can run that code in the visitor's browser, which is called cross-site scripting (XSS).
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.