Skip to content

Lesson 10 of 13 · 15m

go.sum, GOPRIVATE, and Supply-Chain Hygiene

The checksum transparency log, MVS picking lowest-not-latest, GOPRIVATE against dependency confusion, and govulncheck reachability.

go.sum is the file everyone commits and nobody reads — until a maintainer account is taken over and the difference between "the bits you audited" and "the bits you just downloaded" is the only thing between you and a backdoor. In March 2024 the xz backdoor (CVE-2024-3094) proved a trusted maintainer can ship a trojaned release through normal update channels. Go's module system can't stop a hostile maintainer; it can make tampering detectable — if you let it.

What go.sum and the checksum DB do

Every entry in go.sum is a content hash of a specific module version. The first fetch is verified against sum.golang.org, a transparency log — a Merkle tree run by Google since 2019 — where every module hash is publicly recorded, so silently rewriting history is detectable. There are no signatures: Go modules aren't signed. Authenticity comes from TLS to the proxy, the transparency log, and your pinned go.sum. That chain is the whole mechanism — GOSUMDB=off cuts it.

go mod verify re-checks your module cache against go.sum — run it when a build machine smells wrong. go mod tidy reconciles go.mod/go.sum with what the code imports; CI should fail on a dirty git diff after tidy.

Minimum version selection — the wrong mental model

Everyone trained on npm expects "the resolver picks the newest allowed version." Go does the opposite: Minimal Version Selection picks the lowest version satisfying every require. go.mod declares floors, not ceilings — you get the oldest compatible release, not the shiniest. Consequence: go get dep@latest is an explicit act; routine builds never drift. A CVE in a dependency doesn't pull a surprise minor bump onto your machine on Tuesday — it waits for you to run the command and read the diff. Deliberate beats current, in Go's opinion, and it is correct.

Private modules and dependency confusion

In February 2021, Alex Birsan's dependency-confusion research showed he could claim internal package names on public registries and get corporate builds to pull his code instead. The Go control is GOPRIVATE — a glob like *.corp.example.com that is shorthand for GONOPROXY + GONOSUMDB: matching paths bypass the public proxy and checksum log entirely and fetch over your own authenticated VCS. Public names go through proxy plus sumdb; private names never touch them. Mixing them — a private path that leaks to the public proxy — is how you end up importing a stranger's package under your own import path.

Vendoring

go mod vendor copies every dependency into vendor/ and builds switch to -mod=vendor automatically when vendor/modules.txt exists. You audit the dep once, commit it, and your build works offline and forever; the tradeoff is repo bloat and updates that diff like avalanches. For a service you build and deploy it is optional; for reproducible release artifacts it is the strongest option short of running your own proxy.

When you genuinely have two modules in one repo, go.work (Go 1.18) is the tool — not nested go.mod files you mentally merge.

govulncheck: reachability, not noise

govulncheck ./... analyzes your call graph and reports only vulnerabilities your code can actually reach — unlike a deps-versus-CVE-database scan that flags a vuln in a function you never call. Run it in CI. When it fires, the answer is go get dep@fixed plus go mod tidy — and read the diff, because a hostile-update check is exactly what the xz lesson was about.

Field notes

  • GOFLAGS=-mod=readonly in CI: the go command refuses to edit go.mod, so a drifted manifest fails the build instead of silently fixing itself.
  • GOPROXY=direct fetches from origin VCS and is what GOPRIVATE implies for the proxy hop — useful for diagnosing "the proxy sees something I don't."
  • go list -m -u all shows what's outdated without changing anything.

Try this

In a scratch module, go get a small dependency, run go mod tidy && go mod verify, and cat go.sum. Then corrupt one hash character and rebuild — read the checksum-mismatch refusal. That refusal is your supply chain working. Now set GOFLAGS=-mod=readonly in CI and make it structural.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.