Skip to content

Lesson 6 of 12 · 22m

Dependency Auditing: Most of Your Code Isn't Yours

Lockfiles, scanners, SBOMs, and the attack classes CVE feeds never see — confusion, hijacks, and install-script backdoors like xz's CVE-2024-3094.

Open your node_modules. A "small" Express app pulls in a few hundred packages and several hundred thousand lines of strangers' code — every one a liability you imported, and on npm several of them ran install scripts on your machine with your permissions. Dependency auditing exists because you cannot read your supply chain; you can only inventory it and watch it.

The lockfile is the contract

npm ci          # installs exactly what package-lock.json pins — CI, always
npm install     # may resolve NEWER versions inside semver ranges — dev machines

npm install in CI quietly re-resolves the tree, meaning the artifact you shipped isn't the tree you scanned. npm ci fails when the lockfile and manifest disagree — that failure is the feature. Same rule everywhere: pip install -r requirements.txt --require-hashes, cargo build --locked, go build -mod=readonly (the default since Go 1.16), yarn install --immutable.

Scan the lockfile, not the intent

osv-scanner scan source .            # OSV database, multi-ecosystem, reads lockfiles
npm audit --audit-level=high          # the quick npm-native check
pip-audit                             # Python
cargo audit                           # Rust — the RustSec advisory DB
govulncheck ./...                     # Go: does real call-graph reachability

Two things juniors miss:

  • Findings are mostly transitive. The vulnerable package usually sits three levels deep — npm ls <pkg> shows which parent pulled it in, and the fix is often bumping the parent, not the leaf.
  • Severity isn't reachability. govulncheck is what good looks like: it traces whether your code calls the vulnerable function and only reports the paths that execute. A critical CVE in a test helper that never ships is noise; a medium in your request-parsing path is not.

The attack classes no CVE feed covers

  • Dependency confusion. Your internal @acme/utils doesn't exist on the public registry, so an attacker publishes it there with version 99.0.0 and your resolver prefers it. Alex Birsan ran this against Apple, Microsoft, PayPal, and two dozen others in February 2021 — one npm publish, ~$130k in bounties. Fix: publish a placeholder to the public name, force a private registry for scoped packages in .npmrc, and never let --extra-index-url resolve internals publicly (pip prefers the highest version across indexes).
  • Maintainer compromise and sabotage. event-stream absorbed flatmap-stream in 2018 to steal Copay bitcoin wallets; coa, rc, and ua-parser-js were hijacked in late 2021 to drop miners and stealers; colors and faker were deliberately broken by their own author in January 2022. No scanner flagged any of it — the packages did exactly what compromised packages do.
  • Build-script backdoors. xz 5.6.0/5.6.1 (CVE-2024-3094, March 2024) hid an OpenSSH backdoor in m4 build scripts and binary "test" blobs that no source review would catch. A scanner sees "xz, version 5.6.1"; only the advisory connects it to your image.
  • Typosquatting. reqests for requests. Caught by lockfile discipline and review, not feeds.
  • Install scripts. preinstall/postinstall run arbitrary code at install time. npm ci --ignore-scripts kills the class for packages that don't need it — most don't.

SBOMs: the inventory that pays later

syft . -o cyclonedx-json=sbom.json    # or: npx @cyclonedx/cyclonedx-npm

The day the next log4shell drops — Log4j 2's JNDI lookup, CVE-2021-44228, disclosed December 9, 2021 — the question is "do we ship it, anywhere?" An SBOM per release answers in minutes. Without one you're grepping lockfiles across forty repos at 2am; I've done that weekend and don't recommend it. Store SBOMs next to the artifacts, not in a wiki.

Field notes

  • Pair scanning with automated update PRs (Renovate, Dependabot) grouped by ecosystem. A scanner producing findings nobody can land is a guilt generator.
  • npm audit fix --force happily bumps major versions and breaks your app. Read the diff it proposes.
  • Vendored dependencies (a checked-in third_party/) are invisible to lockfile scanners — scan the files, not just the manifests.
  • npm audit signatures verifies the registry's Sigstore signatures on installed packages — cheap proof the bits match what was published.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.