Engineering teams usually look after direct dependencies. They know which packages they added, more or less what those packages do, and who keeps them. Transitive dependencies, the packages those packages pull in, get a sliver of that attention, since no developer ever picked them. They came along with the choices that were made.
A mid-size Node.js application tends to run ten to twenty transitive packages for every direct one. What a developer declared in package.json is a thin slice of the installed surface. Everything nobody chose is nearly the whole thing.
Why the buried layer holds the risk
Attackers did this arithmetic long ago. A popular direct dependency is watched: maintainers are known, the changelog gets read, and researchers tend to notice odd behavior in something pulled five million times a week. A transitive package sitting two or three levels down may have one owner, next to no visibility, and installs that reflect being dragged in rather than being wanted.
Targeting the graph means targeting nodes that are broadly connected and thinly watched. A package carried by a hundred popular libraries reaches far more applications than any one library's direct dependency, while drawing proportionally less scrutiny because nobody knowingly added it.
Several prominent incidents followed this shape. The compromised package had not been installed by any application developer. It sat as a transitive dependency, frequently several hops from the application's manifest, pulled in by something the team trusted.
What manifest-only scanning cannot see
Tools that read the manifest, whether package.json or requirements.txt, see only the top layer. Let a manifest declare forty direct dependencies with twenty transitive apiece, and the scan covers forty packages while the resolved install holds eight hundred or more.
Manifest scanning still earns its place. It is fast and cheap and catches many classes of problem. The trouble comes when it is the only check, because attacks that spread through the transitive layer — most of them, in practice — fall outside what it can see.
What scanning should read instead is the resolved graph: the packages that will actually be installed, not the declared subset. Getting there takes more than opening the manifest. It means running the resolver, capturing the full output, and scanning that.
How the graph resolves
Nothing about transitive risk makes sense without the resolution mechanics underneath it.
npm starts from the declarations in package.json. For each direct dependency it fetches that package's own package.json from the registry and reads the dependencies listed there, then repeats the process for each of those, recursively, until every needed package has a specific version. The lockfile records the outcome: every package in the tree mapped to a version and a hash, nested or flattened.
Version conflicts can place one package at several versions in the same tree. The resolver picks which version applies where, following the algorithm of the package manager. Given identical inputs, those picks are deterministic, yet they can still surprise anyone when a package's transitive dependencies clash with each other or with something declared directly.
Security depends on recognizing that the lockfile's final tree, not the manifest, is the attack surface. A hostile package arriving through a transitive dependency at any depth still installs in full, with the same execution rights as anything declared at the top.
Scoring risk in the transitive layer
Reading the whole resolved tree fixes visibility and creates a volume problem. Eight hundred packages in the tree, three hundred of them carrying a known CVE somewhere on the severity scale, and an alert on every one becomes noise no team can absorb. Much of that exposure lives in code paths the application never touches.
Scanning works when it scores different packages differently rather than assigning every CVE in every transitive package the same weight. The factors that matter most:
- Reachability: Can the application's execution actually reach the vulnerable path? A code execution flaw in a function nothing calls is a smaller near-term problem than the same flaw in a function hit on every request.
- Depth in the graph: One hop off a direct dependency matters more immediately than five, though depth by itself settles nothing.
- Maintainer posture: An anomalous signal on a maintainer account, a recent ownership transfer or an unusual publishing rhythm, deserves investigation whether or not the package carries a CVE.
- Install-time behavior: Any transitive package whose post-install script makes outbound connections jumps in priority regardless of CVE status, since code executing at install is active risk, not a hypothetical.
Updating something you never chose
A vulnerable direct dependency takes one edit: bump the version in the manifest. A vulnerable transitive dependency is harder, because its entry point is not your manifest but the manifest of something you depend on.
Three routes exist, from least to most control: wait for the upstream direct dependency to update and pick it up; override the resolution to force a specific version of the transitive package; or fork the direct dependency and maintain a patch.
Each costs time and effort, which explains why transitive vulnerability management gets deferred so often. Security teams should hold their transitive posture as a living risk register rather than a to-do list, one that guides which dependencies to replace or shrink over time.
Where to begin
Teams doing none of this yet can start with:
- Build the full resolved graph from your lockfiles and keep it with the lockfile, diffing it on each PR so new transitive arrivals surface, not merely direct changes.
- Point early scanning at install-time behavior across the entire tree. A post-install script firing anywhere in the transitive graph is high priority, because that code has already run by the time most post-install checks execute.
- Watch transitive packages whose sole maintainer also runs high download counts, which concentrates risk around account compromise or abandonment.
Zero findings is the wrong target for transitive scanning. The target is shrinking the distance between what developers believe they depend on and what actually runs in the build environment. Most supply chain attacks live in that distance.