Skip to content
XSS Disclosed report Beginner CVE-2019-5458

[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.

lightangel1412 Follow

Originally disclosed on HackerOne

Medium 5.4 View original
  • 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) "
http-file-server_-_XSS2.PNG
http-file-server_-_XSS2.PNG From the original on HackerOne
  • Run 'http-file-server in "~/Desktop" directory :
http-file-server

or

nodejs /usr/lib/node_modules/http-file-server/http-file-server.js
http-file-server_-_XSS0.PNG
http-file-server_-_XSS0.PNG From the original on HackerOne
  • When mouseover event is trigger, a message will be popup via XSS vulnerability.
http-file-server_-_XSS.PNG
http-file-server_-_XSS.PNG From the original on HackerOne

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.

The original report as published on HackerOne, by lightangel1412. 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 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

  1. Install the http-file-server module globally.
  2. Create a file in the served directory whose name contains HTML event-handler code.
  3. Start the server in that directory.
  4. Open the server's directory listing in a browser.
  5. 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.

More by lightangel1412

View all

5 more disclosed reports, best first.

More from Node.js third-party modules

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.