Dev.to Security 🔐 Cybersecurity 👁 0 📖 4 min read

npm audit runs after the damage is done

Your dependency scanner runs too late — and here is what a pre-install check actually sees. Installing a dependency is remote code execution by design. npm install resolves a tree you did not read and runs postinstall

npm audit runs after the damage is done

Your dependency scanner runs too late — and here is what a pre-install check actually sees.

Installing a dependency is remote code execution by design.

npm install resolves a tree you did not read and runs postinstall hooks
before you have looked at the package once. A Python sdist runs a build
backend. A maintainer account can change hands between two releases.

And the tools most of us reach for answer a question that starts after that
moment:

  • npm audit tells you that a version already in your lockfile has a known advisory. The install hook has already run.
  • Dependabot and Renovate track updates to dependencies you already trust.
  • OSV-Scanner reads lockfiles, which exist only after the install.

That gap — the few seconds where you decide to trust a package — is where
supply-chain attacks live. [email protected] is the shape of it: one added
dependency whose only job was a postinstall hook. Transitive, invisible in
package.json, and already running by the time an audit exists.

I built Dep-Vet to check that
moment. It is a single Rust binary that never installs or executes the package
it inspects.

Dep-Vet flagging the crossenv typosquat, then verifying an archive

What a pre-install check can actually see

For a package and an exact version, Dep-Vet reads public registry metadata and
OSV, then asks:

  • Which advisories apply to this version, and which have fixes?
  • Is any CVE behind them in CISA KEV, or carrying a high EPSS score?
  • Does npm run preinstall/install/postinstall — and what do those commands do?
  • Is the name one edit away from something popular, or from something already in my lockfile?
  • Who published this version, and have they published this package before?
  • Is there a provenance attestation, and for npm does its subject digest match the tarball?
  • What does the source repository's OpenSSF Scorecard say?
  • What license is declared?
  • What is inside the release archive, without executing it?

Every finding links to the record that produced it. No risk score, because a
number hides which signal fired and how strong the evidence is.

$ npx @nassihyas/dep-vet npm crossenv
npm/[email protected]

  verdict      HIGH (exit 2)
  first seen   2017-07-19
  published    2017-08-02
  maintainers  npm

  1 finding

  [HIGH]  name is close to a popular package
        'crossenv' is 1 edit(s) away from the popular package 'cross-env'
        -> https://www.npmjs.com/package/crossenv/v/0.0.2-security

It also audits an installed tree, diffs a lockfile against a base branch,
resolves an npm range or a Maven POM tree before install, inspects a release
archive, compares two releases, and scans GitHub Actions and MCP configs.

The rule I care about most: exit 3

Most tools have two outcomes: findings or no findings. Dep-Vet has three, and
the third is the important one:

Code Meaning
0 clean, or informational findings only
1 warnings
2 high risk
3 the check could not run or could not finish

Exit 3 is not a verdict. It means a registry was down, a lockfile line could
not be parsed, or a package could not be fetched. An incomplete audit is never
reported as clean, because "we could not check" and "nothing is wrong" are
different facts.

This matters in CI. A script can fail the build on 2 and treat 3 as an
infrastructure problem, instead of silently passing a half-checked tree.

Then I ran it against a real project

The best test was not a fixture. It was a real, deliberately vulnerable app:
OWASP NodeGoat. The run is pinned to one
commit in examples/nodegoat.

Two things happened.

First, the audit did its job: it resolved 1,090 packages and found dozens of
real advisories on old pinned versions.

Second, it ended with exit 3, not 2. One dependency in that 2023 lockfile,
[email protected], no longer exists on npm. Dep-Vet refused to call the tree
clean because one package could not be checked. That is the exit-code contract
working in public.

And it found two bugs in Dep-Vet itself. Real npm packuments contain shapes the
fixtures did not: scripts values that are objects instead of strings, and a
repository field that is a list of objects. Both used to fail the whole
package parse. Both are fixed now, with regression tests.

That is the argument for dogfooding a security tool: the awkward input finds you
before a user does.

Try it without installing anything

npx @nassihyas/dep-vet npm [email protected]
npx @nassihyas/dep-vet audit package-lock.json
npx @nassihyas/dep-vet guard --check -- npm i express

Or in CI, the reusable action diffs a pull request's lockfile and keeps one
comment updated:

name: dependency review
on: pull_request
permissions:
  contents: read
  pull-requests: write
jobs:
  dep-vet:
    uses: nassih-yassine/Dep-Vet/.github/workflows/[email protected]

For agents, there is a Claude Code hook and an MCP server. Here is OpenCode
blocking an install through MCP:

OpenCode calling dep-vet's vet_command over MCP and blocking npm install crossenv

What it does not do

It is not a replacement for npm audit, Socket, or Dependabot. It adds the
pre-install layer they skip.

  • It does not execute package code or extract archives to disk.
  • It does not model transitive dependencies for a single-package check; use a lockfile audit or plan for that.
  • It does not evaluate Maven profiles or multi-module reactors.
  • It does not assign a score, and no LLM is in a verdict.
  • Workflow and MCP scans are text passes with documented blind spots.

Coverage is honest per registry. npm, PyPI, crates.io, and Composer expose the
most metadata. Go exposes advisories and versions. Anything a registry does not
publish appears as not checked, not as a pass.

Feedback is more useful than stars

If you try it, the useful reports are false positives and missing ecosystems,
especially:

  • a finding you believe is wrong, with the package and version;
  • a lockfile format it misreads;
  • a workflow or MCP config pattern it misses.

Repo: https://github.com/nassih-yassine/Dep-Vet

MIT, no account, no API key, no analytics. One opt-outable update check is the
only request that isn't a registry, advisory, or archive fetch.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.