[http-file-server] Stored XSS in the filename when directories listing
The http-file-server module lists filenames in HTML without sanitisation, so a file with a crafted name containing script code is stored on the server and executed in a visitor's browser when they view the directory listing. An attacker could run arbitrary JavaScript in the context of the server's origin.
Originally disclosed on HackerOne
- Disclosed after 3 months
I would like to report Stored XSS in module "http-file-server". It allows to inject malicious scripts in the file name, store them on the server, then execute these scripts in the browser via the XSS vulnerability.
Module
module name: http-file-server version: 0.2.6 npm page: `https://www.npmjs.com/package/http-file-server
Module Description
Simple HTTP file server (Node.JS)
Module Stats
[0] downloads in the last day [1] downloads in the last week [47] downloads in week 02-08 Apr 2019 [40] downloads in week 09-15 Apr 2019 [120+] downloads in the last month
Vulnerability
Vulnerability Description
This XSS vulnerability occurs due to the module represents filename(s) in HTML without any sanitization in listing directory page. In a result, any malicious scripts which are injected and stored on the server, would be executed in the client's browser.
Steps To Reproduce:
- Install the module
npm install -g http-file-server
- In the directory which will be served via http-file-server, create file with following names in directories ~/Desktop/:
" onmouseover=alert(1) "

- Run 'http-file-server in "~/Desktop" directory :
http-file-server
or
nodejs /usr/lib/node_modules/http-file-server/http-file-server.js

- When mouseover event is trigger, a message will be popup via XSS vulnerability.

Patch
User input should be properly sanitized and filtered both at the client and server side. Dangerous characters such as < > ' " % ; ) ( & + should either be disallowed or HTML encoded before displaying them on screen.
Supporting Material/References:
- Linux kali 4.15.0-kali2-amd64
- node 10.15.3
- npm 6.9
- Firefox ESR 52.7.3 (64-bit)
Wrap up
- I contacted the maintainer to let them know: N
- I opened an issue in the related repository: N
Impact
It allows to inject malicious scripts in the file name, store them on the server, then execute these scripts in the browser via the XSS vulnerability.
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 directory listing page inserts filenames directly into HTML without escaping or sanitising them.
Impact
An attacker could store malicious script in a filename so it executes in the browser of anyone viewing the directory listing.
What the attacker needed
Attacker can create a file with a crafted name; victim visits the directory listing
The fix
User input should be properly sanitised and filtered on both client and server sides, with dangerous characters disallowed or HTML-encoded before display.
How it was found
- Install the http-file-server module globally.
- Create a file in the served directory whose name contains HTML event-handler code.
- Start the server in that directory.
- Open the server's directory listing in a browser.
- Trigger the event (e.g. mouseover) to execute 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 file server shows a list of files in a folder as a web page. If a filename contains special characters that look like HTML code, the server puts them into the page without cleaning them up. When someone opens that page, their browser runs the hidden code as if it were part of the website, 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.