Skip to main content
LowSupply chainOWASP A05:2021CWE-548

How to fix: Asset served directly out of node_modules

A script or stylesheet on this page has a URL containing a /node_modules/ path segment. The dependency directory itself is therefore mapped into the web root.

Why it matters

The whole dependency directory is reachable, not just the file the page asks for. That means every package's package.json, its README, its source maps, its test fixtures and any .env or config file a package happens to ship are all fetchable by path. It also gives an attacker an exact version oracle: requesting node_modules/<pkg>/package.json returns the installed version of anything they care to name.

This is a build-pipeline shortcut rather than a deliberate choice: it happens when a static server is pointed at the project root so a library can be referenced without a bundler step. The dependency inventory it leaks is the mild half. The real risk is the files inside packages that were never meant to be served, and the exact-version oracle, which turns any published advisory into a confirmed hit.

How to fix it

  1. 1Bundle or copy the specific files you need into a build output directory, and serve only that directory.
  2. 2Never point a static-file middleware at the project root or at node_modules.
  3. 3If a directory mapping is unavoidable, deny access to package.json, source maps and dotfiles beneath it.

Code examples

Copy the file into the build output instead

JSON
{
  "scripts": {
    "prebuild": "cp node_modules/chart.js/dist/chart.umd.js public/vendor/chart.js"
  }
}

Express: serve the build output only

JavaScript
app.use(express.static(path.join(__dirname, 'public'), { dotfiles: 'deny' }));
// never: app.use('/node_modules', express.static('node_modules'))

References

Detected automatically by VulnRadar. The check id is supply-chain-node-modules-path-served, stable across every scan so you can filter or diff on it.

See every supply chain check

Questions

How severe is Asset served directly out of node_modules?
VulnRadar rates this low severity in the supply chain category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id supply-chain-node-modules-path-served, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does Asset served directly out of node_modules map to?
It maps to CWE-548. In the OWASP Top 10 it falls under A05:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for asset served directly out of node_modules

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

Asset served directly out of node_modules fix | VulnRadar