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 withnpm ci, notnpm install, so CI builds the exact tree you reviewed.go mod verifychecks the tree againstgo.sum. - Install scripts are code execution.
preinstall/postinstallrun with your shell; usenpm install --ignore-scriptswhen 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-padfor; 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 auditonly 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?
Keep reading
Related articles from the SudoSecurity blog.
What is Go? The Language Google Built for Production Engineering
Go is a statically typed, compiled language built at Google in 2009. It compiles to a single binary with no runtime dependency, starts in milliseconds, and handles concurrency through goroutines and channels. Docker, Kubernetes, and Terraform are all written in Go. Here is why.
What is Rust? The Language That Makes Systems Programming Safe
Rust eliminates entire categories of bugs — null pointer dereferences, buffer overflows, data races, use-after-free — at compile time with no runtime overhead. Microsoft, Google, Amazon, and the Linux kernel all use it for systems code.
What is Java? The Language That Runs Minecraft, Your Bank, and Half the Internet
Java has been declared dead approximately forty times since 1995. It still runs Minecraft, Android, LinkedIn, Twitter's backend, and the financial systems that process your paycheck. Here is what the language actually is, how the JVM works, and why it refuses to die.
What is Python? Enterprise, Data Science, and the Backend of the Web
Python runs Instagram, Dropbox, Netflix, Spotify, and Reddit. It trains the models that power modern AI. It processes petabytes of data in enterprise pipelines. And I ignored it for years because I thought it was just for academics. Here is what changed my mind.