Skip to content

Lesson 11 of 14 · 20m

Dependencies Are Strangers' Code in Your Process

npm install grants maintainers you never vetted code execution with your credentials — lockfiles, scoped registries, and deliberate upgrades are the mitigation.

Here is what actually happens when you run npm install left-pad: you download a maintainer's postinstall script, a transitive graph of strangers' packages, and their release pipeline, and all of it executes with your app's credentials — filesystem, network, environment variables. A dependency is not a function you borrowed. It's someone's code running in your process, and there is no sandbox.

Supply chain is the attack surface now

Attackers learned this before defenders did. In June 2023 the fractureiser malware spread through Minecraft modpacks on CurseForge — drop a JAR into plugins/ or mods/ and it runs as your JVM, stealing session tokens at scale. In November 2018, event-stream — a package pulled deep into the Node ecosystem — gained a new maintainer who added flatmap-stream, a dependency carrying an encrypted payload that only activated inside Copay bitcoin-wallet builds. It sat in production dependency trees for two months.

Then xz. In March 2024, "Jia Tan" — a pseudonymous contributor who spent roughly two years earning commit and release rights on xz Utils — shipped versions 5.6.0 and 5.6.1 with a backdoor smuggled in through test files and the build system. liblzma links into sshd on most Linux distributions; the payload hooked RSA_public_decrypt via IFUNC indirection to bypass authentication — CVE-2024-3094, CVSS 10.0. It was caught almost by accident: Andres Freund noticed sshd burning about 500ms too long under benchmarks. The maintainer was the vulnerability.

Non-malicious dependencies break you too

March 23, 2016: Azer Koçulu unpublished left-pad, an eleven-line function, and Babel and thousands of builds broke within the hour. No CVE, no attacker — just a graph so deep that one node's disappearance was a global outage. In February 2021, Alex Birsan collected about $130k in bug bounties by uploading internal-looking package names to public registries; Apple's, Microsoft's, and PayPal's build systems resolved them and executed his code. Dependency confusion isn't exotic — it's a namespace collision your resolver silently resolves in the attacker's favor. And Log4Shell (CVE-2021-44228, December 2021) lived inside a transitive logging dependency that half the JVM world didn't know it shipped.

The discipline

  • Lockfiles are the contract. Commit package-lock.json, Cargo.lock, poetry.lock, go.sum — and install with npm ci, not npm install, so CI builds the exact tree you reviewed. go mod verify checks the tree against go.sum.
  • Install scripts are code execution. preinstall/postinstall run with your shell; use npm install --ignore-scripts when you don't need them.
  • Count the tree, not the package. npm ls, cargo tree, pipdeptree — a one-line helper that pulls 200 transitive packages is a 200-maintainer trust grant.
  • Prefer the standard library. Go's stdlib covers the territory Node needed left-pad for; every avoided dependency is a maintainer you don't have to vet.
  • Pin digests, upgrade deliberately. Lockfiles plus scheduled, reviewable bumps (Renovate, Dependabot — they're fine because upgrades stay visible) beat floating version ranges silently changing under you.
  • Internal names go private. A scoped private registry for internal packages is what actually stops dependency confusion — the public resolver never gets the chance to guess.

Before adding anything, run the five-second vet: is it maintained (last commit, open CVEs on osv.dev/cargo audit/npm audit)? How many maintainers — a one-person bus factor is a supply-chain and a resilience problem. Does your stdlib or an already-imported dep cover it? And what does it actually do — a CSV parser shouldn't need network permissions.

Pitfalls

  • Vendoring makes you the maintainer — now you track their CVEs forever.
  • npm audit only measures known-bad; it cannot see a maintainer turned, which is the xz scenario.
  • A lockfile you never regenerate is fossilized risk. Upgrades are hygiene, not events.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.