How to fix: npm/yarn Lock File Exposed
A package-lock.json or yarn.lock file was found accessible at a public URL. Lock files contain the exact dependency tree including all transitive dependencies and their versions, enabling an attacker to identify vulnerable packages.
Why it matters
Exposed lock files allow attackers to build a precise vulnerability map: exact dependency versions, dependency tree structure, and package registry sources. Combined with public CVE databases, this turns reconnaissance from hours to minutes.
Lock files are essential for reproducible builds but should not be publicly accessible. They contain enough information to identify every package version installed, including vulnerable transitive dependencies that don't appear in package.json.
How to fix it
- 1Add /package-lock.json, /yarn.lock, /pnpm-lock.yaml to your web server's deny list.
- 2In Nginx: location ~* /(package-lock\.json|yarn\.lock|pnpm-lock\.yaml) { deny all; }
- 3In Next.js: add a redirect or rewrite to return 404 for these paths.
- 4Ensure your build process doesn't copy lock files to the public output directory.
Code examples
Next.js rewrites to block lock files
// next.config.js
module.exports = {
async rewrites() {
return [
{ source: '/package-lock.json', destination: '/api/not-found' },
{ source: '/yarn.lock', destination: '/api/not-found' },
];
}
};References
Detected automatically by VulnRadar. The check id is supply-chain-lockfile-exposed, stable across every scan so you can filter or diff on it.
More supply chain checks
- MediumPython Requirements File Exposed
- MediumRuby Gemfile or Gemfile.lock Exposed
- MediumExternal CDN Script Without SRI Hash
- HighHTTP Script Loaded on HTTPS Page
- MediumPHP composer.json or composer.lock Exposed
- HighDockerfile or docker-compose.yml Exposed
- Critical.env File Exposed at Public URL
- MediumCDN Script With No Version Pin and No Integrity Hash
Questions
- How severe is npm/yarn Lock File Exposed?
- VulnRadar rates this medium 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-lockfile-exposed, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does npm/yarn Lock File Exposed map to?
- It maps to CWE-200. 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.