Lesson 1 of 9 · 24m
Mapping the Dependency Graph Before It Eats You
Inventory direct and transitive dependencies, package managers, install hooks, build plugins, and machine identities so hidden trust becomes visible.
The first time I reviewed a supposedly small Node service, the repository had eleven direct dependencies. The build graph had 1,347 packages, forty-one postinstall scripts, and three separate copies of the same JSON parser. Nobody had chosen that system. It had accreted one npm install at a time. Supply-chain defense starts by accepting that your dependency graph is production code you did not write.
Direct dependencies are the visible edge
Start with manifests, but do not stop there. Every ecosystem has at least two layers: the dependencies you deliberately selected and the transitive closure your package manager selected for you:
npm ls --all --omit=dev
pipdeptree --reverse
cargo tree --edges normal,build
go mod graphCount packages, maintainers, native modules, install scripts, and build-time-only dependencies. A test-only package can still execute on a developer workstation or CI runner, so "not shipped" does not mean "not dangerous."
Build the trust inventory
For each meaningful package, record:
package ecosystem direct/transitive execution surface owner
express npm direct runtime OpenJS community
node-gyp npm transitive build scripts/native npm ecosystem
urllib3 PyPI transitive runtime network client Python maintainers
esbuild npm transitive binary download/build evanw"Execution surface" matters more than repository stars. Runtime packages execute in production. Build packages execute in CI. Install hooks execute at dependency installation time, often with broad environment access. Developer-only CLIs execute with the keys on a laptop. Different exposure, different control.
Follow the machines and credentials
Dependencies do not attack abstractions; they execute somewhere. Draw the machine identities that consume them:
developer laptop -> npm/PyPI -> git checkout -> local secrets
CI runner -> registry -> build artifact -> deploy credentials
production host -> artifact -> runtime service -> customer data
release job -> signing key/package token -> registry publishA malicious transitive dependency in CI may never enter the artifact but can still steal a registry token, cloud role credentials, or signing keys. Conversely, a runtime dependency in production may have no outbound network permission if egress is controlled. Context determines blast radius.
Shadow dependencies count too
Vendored code, copied snippets, Docker base images, GitHub Actions, pre-commit hooks, language servers, IDE extensions, and curl-piped installers all belong in the graph. A repository that pins npm packages but runs actions/checkout@master has simply moved the mutable trust edge.
Field notes
- Count maintainers, not only packages. Thirty packages controlled by one account have a different risk shape from thirty independent projects.
- Look for abandoned packages with high download counts; popularity is not maintenance.
- Package-manager output lies when optional or peer dependencies differ by platform. Generate the graph on the same OS as the build.
- Keep one inventory per deployable artifact. Monorepos often hide radically different exposure behind one lockfile.
Was this lesson helpful?