Learning center

Does an npm audit finding in a devDependency need fixing?

Only if the vulnerable code ships in your build output or runs on input you do not control, such as pull request content in CI. Check both with evidence: the bundler's list of inputs, and the call sites that feed the package. "dev" in package.json records how npm installs a package, not what your bundler includes.

What the dev label does and does not tell you#

npm's package.json documentation at v10.9.9 gives devDependencies a narrow meaning: someone using your module "probably don't want or need to download and build the external test or documentation framework that you use", so you list those packages separately and npm skips them when your package is installed as a dependency. That is an install rule. A bundler such as esbuild follows import statements, and it bundles a package from node_modules whichever section of package.json lists it.

npm audit --omit=dev applies the install rule to the report. The npm-audit documentation says that if any --omit options are specified, "then packages will be omitted from the submitted payload as appropriate." The omitted packages are not checked at all, so a clean --omit=dev report says nothing about a dev package that the bundle pulls in.

A project with two dev findings#

This constructed project builds a small browser widget with esbuild. Its one runtime dependency is ms. Its devDependencies are esbuild@0.24.0 for the build and minimist@1.2.5, which a fixture generator uses. With Node 22.23.5 and npm 10.9.9 against the public registry:

$ npm audit
esbuild  <=0.24.2
Severity: moderate
esbuild enables any website to send any requests to the development server and read the response - https://github.com/advisories/GHSA-67mh-4wv8-2f99
node_modules/esbuild

minimist  1.0.0 - 1.2.5
Severity: critical
Prototype Pollution in minimist - https://github.com/advisories/GHSA-xvch-5gv4-984h
node_modules/minimist

2 vulnerabilities (1 moderate, 1 critical)
$ npm audit --omit=dev
found 0 vulnerabilities

(The fix available lines are trimmed.) npm ls and npm explain show that both packages are direct dev dependencies, with no production path:

$ npm ls minimist esbuild ms
report-widget@1.0.0
+-- esbuild@0.24.0
+-- minimist@1.2.5
`-- ms@2.1.3
$ npm explain minimist
minimist@1.2.5 dev
node_modules/minimist
  dev minimist@"1.2.5" from the root project

That establishes the install path, not the execution path. Two more facts decide each finding.

Check what ships and what feeds the package#

First, what the bundle contains. esbuild writes a metafile listing every module it bundled:

$ npx esbuild src/index.js --bundle --minify --outfile=dist/widget.js --metafile=meta.json
$ node -e "console.log(Object.keys(require('./meta.json').inputs).join('\n'))"
node_modules/ms/index.js
src/index.js

Neither flagged package is in the output. Second, where each package runs and on what input. The esbuild advisory concerns the development server: per GHSA-67mh-4wv8-2f99, "esbuild sets Access-Control-Allow-Origin: * header to all requests, including the SSE connection". The minimist advisory, GHSA-xvch-5gv4-984h, says it "is vulnerable to Prototype Pollution via file index.js, function setKey()", so the risk turns on who controls the arguments being parsed. The call sites:

$ grep -rn --exclude-dir=node_modules --exclude-dir=bundled --exclude=package-lock.json -E "minimist|fixtures|serve" package.json ci scripts src
package.json:7:    "fixtures": "node scripts/gen-fixtures.js"
package.json:14:    "minimist": "1.2.5"
ci/test.sh:4:npm run fixtures -- --count 50
scripts/gen-fixtures.js:1:const minimist = require("minimist");
scripts/gen-fixtures.js:2:const args = minimist(process.argv.slice(2), { default: { count: 10 } });
scripts/gen-fixtures.js:4:require("fs").writeFileSync("test/fixtures/rows.json", JSON.stringify(rows));

Nothing starts esbuild's server; the build uses --bundle only. minimist parses one argument list, written in the repository's own CI script. Both findings can be dismissed with that evidence recorded, and both upgrades can wait for the next routine dependency update. The dismissal stops holding if a developer runs esbuild --serve on a workstation (the advisory's attack is a web page reading the local dev server) or if a workflow passes text from a pull request title, branch name or comment into the fixture script.

When a devDependency ships in the bundle#

The disconfirmation is a dev package your source imports. A copy of the same project adds lodash@4.17.20 with npm install -D lodash@4.17.20 and uses its template function in the widget:

import ms from "ms";
import template from "lodash/template";
const line = template("updated <%= age %> ago");
export function renderAge(createdAt) {
  return line({ age: ms(Date.now() - createdAt, { long: true }) });
}

The production-only audit stays clean, because lodash is listed as dev and so is never submitted:

$ npm explain lodash
lodash@4.17.20 dev
node_modules/lodash
  dev lodash@"^4.17.20" from the root project
$ npm audit --omit=dev
found 0 vulnerabilities
$ npm audit
lodash  <=4.17.23
Severity: high
Command Injection in lodash - https://github.com/advisories/GHSA-35jh-r3h4-6jhm
...

The full audit lists four lodash advisories (trimmed above). The metafile shows the vulnerable module in the shipped file:

$ npx esbuild src/index.js --bundle --minify --outfile=dist/widget.js --metafile=meta.json
$ node -e "const i=Object.keys(require('./meta.json').inputs);console.log(i.length+' inputs');console.log(i.filter(x=>/template|ms\/|src/.test(x)).join('\n'))"
74 inputs
node_modules/ms/index.js
node_modules/lodash/templateSettings.js
node_modules/lodash/template.js
src/index.js

The bundle grew from 2 inputs to 74, and lodash/template.js is one of them. GHSA-35jh-r3h4-6jhm reads "lodash versions prior to 4.17.21 are vulnerable to Command Injection via the template function." Whether this widget's fixed template string is exploitable is a separate question for that advisory; what this evidence settles is that the code ships, so the finding is a production finding. Upgrade lodash, move it to dependencies so production-only audits see it, and keep the metafile check in CI so the next mislabeled import shows up.

The same flip applies without a bundler. A markdown linter or a code generator listed as dev, run by CI on files a pull request author controls, processes untrusted input on a runner that may hold secrets. Treat its advisory by what the CI job exposes, not by its section in package.json.

Decide from the bundle and the call sites#

What the finding saysEvidence to collectDecision
Advisory in a dev package, --omit=dev cleanBundler metafile or stats listing bundled modulesDismiss for production only if the package is absent from the output
Dev tool's server or watch mode affectedWhether any script or developer runs that modeDismiss if unused; otherwise upgrade, since workstations are exposed
Parser or renderer in a dev packageWhat input CI passes it, and who controls that inputDismiss for fixed input; fix if pull request content reaches it
Dev package present in the bundle's inputsnpm explain plus the importing source fileFix as a production finding; move it to dependencies
Only npm audit --omit=dev was runA full npm auditRun the full audit before deciding

When npm lists the flagged package more than once at different versions, the guide to duplicate package versions shows how to find the copy your code loads. For the pull request that a dependency bot opens to fix such a finding, see the dependency bot review guide.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading