Skip to content

Lesson 8 of 14 · 13m

Hashes, Vendoring, and Not Trusting the Network

pip --require-hashes, go.sum's transparency log, and vendoring move trust from the channel to the bytes.

When the hash is the whole policy

pip install --require-hashes -r requirements.txt changes pip's contract: every artifact in the file must carry a sha256, and pip refuses to install anything whose bytes don't match. Generate the file with pip-compile --generate-hashes (pip-tools) or uv pip compile --generate-hashes and you get a pinned, hashed tree:

requests==2.32.3 --hash=sha256:70761cfe03c773ceb22aa2f671b4757976145175cdfca038c02654d061d6dcc1

Now a swapped artifact on PyPI — same name, same version, different bytes — fails the install instead of silently shipping. This is the strongest client-side integrity check pip has, and it costs you one flag and a generated file.

Go solved this differently — and publicly

go.sum holds hashes of the module and its go.mod, but the real trick is sum.golang.org: since Go 1.13 (August 2019), the toolchain records every fetched module's hash in a public, append-only transparency log. Your go.sum hash isn't just checked against the bytes downloaded — it's checked against what the whole world saw when anyone first fetched that module version. An attacker can't serve you a modified github.com/x/y@v1.2.3 without the sum database noticing the discrepancy. go mod verify re-checks the local cache; GOPRIVATE marks path globs that skip both proxy and sum db (correct for genuinely private modules, wrong to abuse); GOFLAGS=-mod=vendor takes the network out of the build entirely.

This is the pattern sigstore's Rekor later generalized: don't just verify content, pin content into a witnessed public log so silent substitution is impossible.

Vendoring: delete the network from the build

The strongest version of integrity is not fetching at all:

  • go mod vendor writes the module tree into vendor/; go build -mod=vendor compiles without touching the proxy. The dependencies become your code — reviewed, committed, immune to registry disappearance and upstream rewrites.
  • cargo vendor plus .cargo/config.toml source replacement does the same for crates.
  • For npm, committing node_modules is theoretically equivalent and practically miserable — the saner version is building the deployable artifact once (a Docker image, a tarball) and shipping that pinned by digest: image@sha256:....

The wrong mental model

"Signed registries make hashes redundant." Registry TLS protects the channel; a compromise of the registry, the account, or the artifact before it hit the CDN defeats the channel while the bytes flow over healthy TLS the whole way. Hashes and transparency logs verify the artifact itself — which is why they survive attacks transport security can't see.

Debian has run the vendoring endgame for thirty years: distro packages are vendored dependencies — reviewed, rebuilt, signed (InRelease/Release over Release.gpg, then per-deb checksums in Packages), and shipped over a channel your apt already trusts. The supply-chain lesson runs both ways: apt's model is exactly "don't trust the upstream network at install time," and its weak point is exactly the one xz exploited — the tarball the distro repackaged.

The flip side deserves honesty too: vendoring trades fetch-time risk for maintenance burden. Vendored code doesn't get npm audited or pip-audited automatically — you're now the distributor. For most teams the right split is hashed lockfiles everywhere, vendoring for deployable artifacts and security-critical paths.

Practice

  • Python production requirements: --generate-hashes + --require-hashes. Non-negotiable for deploy images.
  • Go: commit go.sum, go mod verify in CI, vendor when the deploy artifact allows it.
  • Everything else: lockfile + npm ci/--frozen-lockfile + lockfile-lint, and pin deploy artifacts by digest — docker pull app@sha256:..., not app:latest. A mutable tag is a git branch wearing a version's clothes.

The question hashes answer is narrow and total: are these the bytes I approved? Everything else — registry, CDN, account, channel — is someone else's problem. The residual risk is the moment of approval itself: verify the first fetch, then let the hash keep it honest forever after.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.