Skip to the content ForoHackers
Log inJoin

Threat-modelling your dependencies: what pinning does and does not buy you

Build systemsSecure codingSupply chain security
#993 · ssh_tunnel_vision · · Report

Every project I audit has a requirements.txt or a lockfile and a feeling of safety. So let me do the threat model out loud.

What you trust when you add a dependency 1. The author of that package today. 2. Every author it depends on, recursively. 3. The registry that serves it, and the account that publishes it. 4. Your own build machine and the network between you and the registry.

What can go wrong - A maintainer account is taken over and a malicious release is published. - A name close to a popular one (typosquatting) gets installed by mistake. - A release is yanked and replaced, so "version 1.4.2" is no longer the same bytes tomorrow. - A project changes hands and the new owner publishes something you did not expect.

What pinning gives you - A lockfile with exact versions and hashes (pip install --require-hashes, package-lock.json integrity fields, Cargo.lock checksums) means you get the bytes you reviewed last time, not whatever is newest. That kills the "silent replacement" case.

What it does not give you - Protection from a dependency that was already malicious when you pinned it. - Protection when you update. Updating is where the risk comes back, so it deserves a review of the diff, not just a green CI.

Habits that help: fewer, smaller dependencies; a delay before adopting brand-new releases; a private mirror for production builds; and the unfashionable one, reading what changed.

What is your own rule for accepting an update?

#1362 · git_blame_myself · · Report

Mine, after getting burned: automated update PRs are welcome, but they never auto-merge. Somebody reads the changelog and skims the diff of anything that touches install scripts or network code. It costs ten minutes per update and has already caught one surprise.

#1363 · regex_regret · · Report

"Skim the diff of anything with an install hook" is the part people skip. In Python, a setup.py can run arbitrary code at install time, and in other ecosystems there are equivalents. The install step is code execution on your machine before you have run anything.

#1364 · heap_spray_and_pray · · Report

And the pattern to remember from the defender's side: the dangerous change is rarely the loud one, it is the small one nobody looks at closely. The mitigation is cultural: more than one reviewer on anything that ships, and no single person who can publish alone.

#1365 · ssh_tunnel_vision · · Report

Right. "Two people to publish" is the cheapest control that exists, and few small projects have it. Trust is a process, not a person.

Log in or join to reply.