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

[buttle] HTML Injection in filename leads to XSS when directory listing is displayed in the browser

The buttle static file server renders directory listings using an outdated connect middleware that does not properly escape filenames. An attacker who can create a file with a crafted name can inject an iframe that loads a malicious HTML file, executing JavaScript in the browser of anyone viewing the directory listing.

bl4de Follow

Originally disclosed on HackerOne

Medium 5.2 View original
  • Triaged in 8 days
  • Fixed in 3 months
  • Disclosed after 3 months

I would like to report HTML Injection in buttle module.

Due to lack of filenames sanitization, it is possible to inject malicious iframe tag via filename and execute arbitray JavaScript code.

Module

module name: buttle version: 0.2.0 npm page: https://www.npmjs.com/package/buttle

Module Description

Simple static file (+ markdown) server.

Module Stats

Stats:

N/A, estimated ~20-40 downloads/week

Vulnerability

Vulnerability Description

When buttle displays directory index in the browser, it uses directory.js middleware from connect module to create an output with HTML. Because methods to escape user output used in this middleware are not sufficient enough (it's actually quite outdated version of connect), it is possible to inject iframe tag with src attribute set to arbitrary HTML file, which can contain any executable JavaScript code.

Steps To Reproduce:

  • install buttle:
$ npm i buttle
  • create file with the following name: "><iframe src="malware_frame.html">

  • create malwrae_frame.html file with following content:

HTML
<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="malware.js"></script> -->
    <script>
        alert('Uh oh, I am bad, bad malware!!!')
    </script>
</body>

</html>
  • run buttle:
$ ./node_modules/buttle/bin/buttle -p 8080
Listening on port 8080
  • in browser, open the following url:
http://localhost:8080

You see JavaScript from malware_frame.html executed immediately:

1.jpg
1.jpg From the original on HackerOne

Patch

Probably updating all dependiences is a good solution.

Supporting Material/References:

  • Operating system: Ubuntu 16.04
  • Node.js 8.9.4
  • npm v. 5.6.0
  • Chromium Version 67.0.3367.0 (Developer Build) (64-bit)

Wrap up

  • I contacted the maintainer to let them know: [N]
  • I opened an issue in the related repository: [N]

I hope my report will help to keep Node.js ecosystem and its users safe :)

Regards,

Rafal 'bl4de' Janicki

Impact

An attacker is able to execute arbitrary JavaScript code in user's browser

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 http://localhost:8080

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

Likely the directory-listing middleware from an outdated version of the connect module escapes filenames insufficiently, so HTML in a filename is rendered as markup.

Impact

An attacker could execute arbitrary JavaScript in the browser of a user who views the directory listing.

What the attacker needed

Ability to create files in served directory; victim views the directory listing

The fix

The report suggests updating all dependencies as a probable solution.

How it was found

  1. Install the buttle module.
  2. Create a file whose name contains an iframe tag pointing to a malicious HTML file.
  3. Create the malicious HTML file containing JavaScript.
  4. Start buttle on a port.
  5. Open the server root in a browser and observe the script executing.

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 small web server that lists files in a folder did not clean up file names before putting them into the web page. Someone could name a file so that the page treats part of the name as HTML code, which then loads another file containing JavaScript. When a visitor opens the folder listing, that script runs in their browser.

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.