Skip to content
XSS Disclosed report Beginner

[buttle] Unsafe rendering of Markdown files

The buttle static file server renders Markdown files using the kramed library without sanitising the resulting HTML. An attacker who can place a malicious Markdown file in the served directory could execute arbitrary JavaScript in a victim's browser when the file is opened.

skyn3t Follow

Originally disclosed on HackerOne

  • Triaged in 8 days
  • Fixed in 3 months
  • Disclosed after 4 months

I would like to report Cross Site Scripting vulnerablity in buttle module It allows to execute arbitary javascript due to unsafe rendering of markdown files.

Module

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

Module Description

Another static file server? Why buttle? Well... if you came here looking for a blazing fast server of static files, something with caching and compression options then you're in luck, that does exist! It just isn't buttle.

Buttle is tailored for use in development. It has baked in live reloading for html and markdown files. It'll on-the-fly convert your LESS filess to CSS... and cache nothing because it assumes you're actively hacking away. With buttle you can test drive that angular app you just cloned or maybe have your test runner page refresh whenever a source file is changed.

Module Stats

~0 weekly downloads

Vulnerability

Vulnerability Description

buttle uses kramed for parsing and rendering markdown. By default kramed does not sanitize html. An uninformed user may assume the output of markdown to be sanitized and thus become vulnerable to XSS by rendering malicious markdown files.

See https://github.com/jtrussell/buttle/blob/master/lib/mid-buttle.js

JavaScript
// line no 8
  var md = require('kramed');
  md.setOptions({
    gfm: true
  });

return function(req, res, next) {
    var url = req.url;
    if(/\.md$/i.test(url) || /\.markdown/i.test(url)) {
      fs.exists(j(dir, url), function(exists) {
        if(exists) {
          fs.readFile(j(dir, url), {encoding: 'utf8'}, function(err, data) {
            if(err) { return res.end(err.message); }
            res.end(wrapInHtml(md(data)));
          });
        } else {
          next();
        }
      });
    } else {
      next();
    }
  };

Steps To Reproduce:

  • install buttle:

$ npm i buttle

  • run buttle:

./node_modules/buttle/bin/buttle -p 8080

  • add a malicious markdown file in the server directory (test.md attached) and open it in browser.

Patch

kramed provides an option sanitize which is set to false by default. Either set the santize option to true in line no 11 of mid-buttle.js or inform the user to safely handle markdown files by displaying an apropriate warning.

Supporting Material/References:

Yandex 18.7.0.2767 beta (64-bit) Ubuntu 16.04 node v10.9.0 npm 6.4.1

Wrap up

Select Y or N for the following statements:

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

PS: kramed package is a fork of another library marked and is unmaintained since last 2 years.

Impact

User is exposed to unsafely rendered markdown files which may lead to execution of arbitrary JS

The original report as published on HackerOne, by skyn3t. 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 kramed Markdown parser is used with its default settings, which do not sanitise HTML, and the resulting HTML is served directly to the browser.

Impact

A user who opens a malicious Markdown file served by buttle could have arbitrary JavaScript executed in their browser.

What the attacker needed

Buttle server running; malicious Markdown file in served directory; victim opens the file in a browser

How it was found

  1. Install the buttle package using npm.
  2. Run the buttle server on a chosen port.
  3. Place a malicious Markdown file in the server directory.
  4. Open the Markdown file in a browser.

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.

Markdown is a simple way to format text, and some tools convert it to HTML for display. If that conversion does not clean up dangerous HTML, a file can contain hidden code that runs in the browser. Here, the buttle development server converts Markdown without cleaning it, so a malicious file could run JavaScript when opened.

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 skyn3t

View all

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