← Back to section · Tutorials & Labs
Supply-Chain Hygiene for Cryptography Projects: cargo audit, deny and vet
Every dependency a cryptography project takes on is a potential attack surface. This article lays out a complete supply-chain hygiene pipeline: Cargo.lock and reproducible builds, cargo audit watching advisories, cargo deny enforcing policy, cargo vet recording reviews — and wires them into CI.
Why Cryptography Projects Must Be Extra Strict About Dependencies
A Rust cryptography project’s own code may be only a few thousand lines, but its dependency tree easily exceeds a hundred crates: from rand and getrandom to serialization, networking and logging, all of it written by someone else. An attacker does not need to break your algorithm; planting a backdoor in an inconspicuous dependency, or waiting for a vulnerability to surface in one while you are slow to upgrade, compromises the system from the side. Repeated poisoning and hijacking incidents against package registries prove that the supply chain is one of the most realistic attack surfaces there is. This article lays out a four-layer hygiene pipeline you can adopt directly.
Layer One: Cargo.lock and Reproducible Builds
Application projects (especially cryptographic tools and services) should commit Cargo.lock to version control and build in CI with the --locked flag: dependency versions and checksums are pinned, builds are reproducible, and anyone can later audit “exactly which code went into this binary.” Library crates conventionally do not commit a lock file, but their CI should at least include a channel that runs the full test suite against the newest compatible versions, to surface upstream breakage early. Also build the habit of reading the dependency tree: run cargo tree periodically, and interrogate the provenance of any unfamiliar transitive dependency that suddenly appears.
Layer Two: cargo audit — Watching Published Problems
cargo audit compares your Cargo.lock against the RustSec advisory database and reports three classes of problem: published security vulnerabilities, versions flagged as risky, and unmaintained crates. It is the lowest-cost, highest-return step in CI: a single command, no human judgment needed, intercepts incidents like “shipped a version of an OpenSSL binding with a known hole.” Cryptography projects should go one step further: follow the advisory channels of core dependencies (randomness, TLS, algorithm implementations) directly, because there is a lag between a vulnerability’s disclosure and its entry in the advisory database; high-sensitivity systems should subscribe to upstream security mailing lists rather than waiting for the tool to raise the alarm. A nonzero exit from audit should block the merge, and any exception must be recorded in explicit configuration and re-reviewed periodically.
Layer Three: cargo deny and cargo vet — From Checking to Governance
cargo deny turns policy into configuration: license allowlists (keeping copyleft licenses out of commercial closed-source products by accident), bans on git dependencies of unknown origin, warnings on multiple versions of the same library (three versions of rand sitting in one dependency tree is itself a risk signal), and advisory policy. It answers organizational questions of the form “what is our dependency policy?”
cargo vet goes one step further and answers “who has read this code?” Its model: every dependency either carries a review record from a trusted source (large organizations such as Mozilla and Google publish their review sets for reuse) or is entered in the project’s exemption list with an explicit “not reviewed, because…” note. This is not ceremony: it turns “blindly trusting everything on crates.io” into an explicit, auditable trust list that updates with versions. For cryptography projects, hold the algorithm- and randomness-related crates among your direct dependencies to a higher standard — prefer implementations with public audit reports that fall within vet review coverage — which dovetails exactly with the dimensions in this subcategory’s selection article.
An Interlude: Three Typical Ways Dependencies Go Wrong
To understand why the tools exist, look at the shapes of incidents first. Supply-chain events fall into roughly three classes. First, squatting and impersonation: an attacker registers a name differing from a well-known crate by a letter or two (typosquatting), waiting for a careless developer to mistype a dependency name; the countermeasures are to check dependency names character by character, add only from the official registry, and use cargo deny’s source policy to block non-registry sources. Second, maintainer account compromise: publishing rights to a legitimate crate are stolen and a new version is backdoored; the countermeasures are pinned versions, delayed adoption of major releases, and vet’s review status constraining “unreviewed new versions shall not enter.” Third, a legitimate update to a legitimate dependency introduces a problem: an upstream refactor introduces a vulnerability or a behavior change; the countermeasure is human review plus interoperability testing for cryptography dependency upgrades (see the next layer). The three incident classes map to three different sets of tools and processes — which is why hygiene needs to be a “pipeline” rather than a single point tool.
For high-assurance settings there is one more fallback: cargo vendor pulls the source of every dependency into a local repository, under your own version control and review, and builds run fully offline. It is expensive (repository bloat, entirely manual updates) and generally reserved for classified or strongly regulated projects, but knowing this retreat exists is itself part of supply-chain planning.
The Other Half of the Routine: A Cadence for Version Updates
Supply-chain hygiene is not only about preventing attacks; it is also about keeping pace with fixes. Dependencies left un-upgraded for years are equally dangerous: many high-severity entries in the advisory database hit precisely “lock files untouched for years.” Give dependency updates a fixed cadence — for example, process routine updates in one batch monthly, with advisory-driven emergency updates inserted at any time — and leave the review record of each update (which changelogs were read, which tests were run) in the pull request. The value of cadence is that it turns “should we upgrade?” from a question re-decided every time into a process question with a default answer; for small teams with limited hands, that is the key to a hygiene system that actually survives long-term.
Layer Four: Landing Hygiene in CI and Daily Rhythm
Tools only count once they enter the process. The recommended baseline configuration: every pull request automatically runs cargo audit and cargo deny check; a weekly scheduled job runs a full audit (because new advisories can appear at any time, unrelated to your code changes); and cargo vet re-checks review status whenever dependencies change. Automation such as Dependabot or Renovate delivers upstream releases as pull requests, but pull requests upgrading cryptographic dependencies must never be auto-merged — read the upstream changelog and advisories first, run the interoperability tests, and only then let it through.
The last point is cultural: the number of dependencies is itself a risk metric. Before adding a new dependency, ask three questions: can the standard library or an existing dependency solve this? What is this crate’s maintenance status and audit record? How many transitive dependencies will it pull in? Turning these three questions into a team habit determines the long-term health of the supply chain more than any tool.
Tags: RustSupply Chaincargo auditCI