Skip to content
XSS Disclosed report Intermediate CVE-2018-3770

[markdown-pdf] Local file reading

The markdown-pdf module converts markdown to HTML and then renders it to PDF without sanitising embedded HTML, so a crafted markdown file can include script that runs during rendering. An attacker could use this to read local files on the machine performing the conversion and have their contents written into the resulting PDF.

n1__ Follow

Originally disclosed on HackerOne

Medium 5.3 View original
  • Triaged in 15 days
  • Fixed in 46 days
  • Disclosed after 49 days

I would like to report local file reading in markdown-pdf It allows to insert a malicious html code, which allows to read the local files.

Module

module name: markdown-pdf version: 8.1.1 npm page: https://www.npmjs.com/package/markdown-pdf

Module Description

Node module that converts Markdown files to PDFs.

The PDF looks great because it is styled by HTML5 Boilerplate. What? - Yes! Your Markdown is first converted to HTML, then pushed into the HTML5 Boilerplate index.html. Phantomjs renders the page and saves it to a PDF. You can even customise the style of the PDF by passing an optional path to your CSS and you can pre-process your markdown file before it is converted to a PDF by passing in a pre-processing function, for templating.

Module Stats

778 downloads in the last day 9,801 downloads in the last week

Vulnerability

Vulnerability Description

The markdown-pdf module allows you to convert markdown files to pdf. Due to insufficient filtration of the user input files, exist the possibility of inject a malicious html code.

Steps To Reproduce:

  1. Make the file test.md with following content:
# this is h1
<script>x=new XMLHttpRequest;x.onload=function(){document.write(this.responseText)};x.open("GET","file:///etc/passwd");x.send();</script>
  1. Make the file test.js with following content:
JavaScript
var markdownpdf = require("markdown-pdf"), fs = require("fs")

fs.createReadStream("test.md")
  .pipe(markdownpdf())
  .pipe(fs.createWriteStream("document.pdf"))
  1. Run the script: node test.js
  2. Open the file document.pdf in the same directory

Supporting Material/References:

  • Operating system: Ubuntu 14.04
  • Node.js 9.8.0
  • npm 6.1.0

Wrap up

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

Recommendations fix:

Use html encode for encoding an user content, which not a markdown.

Impact

After converting the file, user can read a local file of system.

The original report as published on HackerOne, by n1__. 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 markdown-to-HTML conversion passes raw HTML through to the renderer without encoding or sanitising it, so script in the document executes with access to local files.

Impact

After conversion, an attacker could read a local file on the system where the conversion runs and have it appear in the PDF.

What the attacker needed

Victim converts an untrusted markdown file; markdown-pdf 8.1.1 installed

How it was found

  1. Create a markdown file containing an embedded script that requests a local file.
  2. Create a small Node script that streams the markdown file through markdown-pdf and writes the output PDF.
  3. Run the Node script.
  4. Open the generated PDF to see the local file contents.

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.

This tool turns a markdown document into a PDF by first turning it into a web page and then rendering that page. Because any HTML in the markdown is kept and run, a document can carry a small script that asks the computer for a local file, such as the system password file, and copies it into the PDF. Anyone who converts an untrusted document with this tool could leak files from their own machine.

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 n1__

View all

1 more disclosed report, 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.