Skip to content
XSS Disclosed report Beginner

[harp] Unsafe rendering of Markdown files

The harp web server renders Markdown files using the marked 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 viewed.

skyn3t Follow

Originally disclosed on HackerOne

  • Triaged in 26 days
  • Fixed in 4 months
  • Disclosed after 4 months

I would like to report Cross Site Scripting vulnerablity in harp module It allows to execute arbitrary JavaScript due to unsafe rendering of markdown files. Similar to #404126

Module

module name: harp version: 0.29.0 npm page: https://www.npmjs.com/package/harp

Module Description

zero-configuration web server with built in pre-processing

Module Stats

3,576 downloads in the last week

Vulnerability

Vulnerability Description

Harp uses marked in their preprocessor terraform for parsing and rendering markdown. By default marked 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/sintaxi/terraform/blob/master/lib/template/processors/md.js

JavaScript
var TerraformError = require("../../error").TerraformError
var marked = require("marked").setOptions({
  langPrefix: 'language-',
  headerPrefix: '',
  gfm: true,
  tables: true,
})
var renderer = new marked.Renderer()
...

Steps To Reproduce:

  • Install harpjs
yarn global add harp
  • Run harp server
harp server 
  • Add malicious markdown file in the server directory (test.md attached) and open it in browser.

Eg:. http://localhost:9000/test will open test.md if it exists in the project directory

Refer http://harpjs.com/docs/development/markdown

Patch

marked provides an option sanitize which is set to false by default. You can also pass a custom sanitizer function through options. Either set the santize option to true in terraform while importing marked or inform the user to safely handle markdown files by displaying an appropriate warning.

Supporting Material/References:

  • Ubuntu 16.04
  • node v11.3.0
  • npm 6.4.1

Wrap up

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

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 marked library was used with its default settings, which do not sanitise HTML embedded in Markdown.

Impact

A user viewing a malicious Markdown file could have arbitrary JavaScript executed in their browser.

What the attacker needed

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

The fix

The sanitize option should be enabled when importing marked, or users should be warned to handle Markdown files safely.

How it was found

  1. Install harpjs globally.
  2. Run the harp server.
  3. Place a malicious Markdown file in the server directory.
  4. Open the file in a browser via the local server URL.

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 tools convert it to HTML for web pages. If that conversion does not clean up dangerous HTML, a file can include code that runs in the browser. Here, the harp server used a converter that left such code in place, so a malicious Markdown 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.