Dependencies and Supply Chain
Most of your attack surface is code you never wrote.
What you will learn
- -Scan a dependency tree for known vulnerabilities
- -Pin versions with lockfiles and hashes for reproducible builds
- -Recognize typosquatting and dependency-confusion attacks
Log4Shell was not your bug. It was your anyway. That is the whole problem with dependencies in one sentence: a typical app pulls in several hundred transitive packages, a Python service drags in dozens, and every one of them runs with your permissions. You your own code carefully and ship someone else's without reading a line.
You cannot rewrite the ecosystem, so the job is managing it: know what you depend on, know when a dependency has a known hole, and how new versions in.
Scan for known vulnerabilities
The is checking your tree against public feeds. When a CVE drops for a library you use, a scanner maps it to your exact versions and tells you which ones to bump. This is free and fast, so there is no excuse for skipping it.
$npm audit --production$pip-audit -r requirements.txt$osv-scanner --lockfile package-lock.jsonWire one of these into CI so a pull request that adds a vulnerable package fails the build instead of merging. Dependabot and Renovate go a step further by opening the upgrade PR for you. Turn them on, but read the diffs, because auto-merging every bump is its own .
Pin so builds are reproducible
An unpinned dependency is a promise that whatever the serves at build time is fine. It is not. Pinning locks your build to exact versions so the same commit produces the same bytes, and a compromised patch release cannot slip in silently overnight.
Lockfiles do most of this: package-lock.json, poetry.lock, Cargo.lock, yarn.lock. They record the exact resolved version of every direct and transitive package. Commit them. For a stronger guarantee, pin hashes too, so the build fails if a package's contents change even under the same version number.
$pip install --require-hashes -r requirements.txtKnow what you ship: SBOMs
When the next Log4Shell lands, the first question in the incident channel is "do we ship the vulnerable library, and where." If you cannot answer in minutes, you are already behind. A software bill of materials, an SBOM, is the inventory that answers it: a machine-readable list of every component in a build, in a format like CycloneDX or SPDX.
$syft dir:. -o cyclonedx-json > sbom.json$grype sbom:sbom.jsonThe attacks that pinning fights
Supply-chain attacks target the trust you place in the registry, and they show up in a few recurring shapes. Typosquatting publishes reqeusts and python-sqlite hoping a fat-fingered install pulls . Dependency confusion your internal package name on the public registry so your build grabs the attacker's version instead of your private one. And a compromised maintainer account can push a malicious patch to a package you already trust, which is how event-stream and ua-parser-js bit thousands of projects.
Pinning, hash verification, and not blindly upgrading blunt all three, because each one depends on your build silently accepting something new. Read what you add. Check the download counts and the repo before you npm install a package you found in a Overflow answer.
Running audits and generating SBOMs against your own projects, or ones you are authorized to assess, is the entire point. Publishing typosquat packages, registering internal names for dependency confusion, or exploiting another organization's unpatched dependency are attacks that require you almost certainly do not have. Learn the shapes so you can defend against them.
Your company uses an internal package named acme-utils, never published publicly. A build starts pulling acme-utils from the public npm registry. What attack is this?