Rust 1.100 stabilizes min-publish-age , better known as dependency cooldowns. Once configured, Cargo’s resolver ignores crate versions that were published too recently. A compromised release gets some time to be noticed and yanked before it lands in your Cargo.lock.

In this article, I’ll enable the cooldown, explain what Cargo does with an existing lockfile, and show how to override it for an urgent security fix.

Why A Cooldown Helps

Without any protection, cargo update happily picks the newest semver-compatible version of every dependency, even if it was published a minute ago. If an attacker takes over a maintainer account and publishes a malicious version, you may pull it in before anybody (including security scanners) had a chance to look at it.

A cooldown trades a bit of freshness for time. Versions have to be available for a while before your project can adopt them.

Enable The Cooldown

Update your toolchain first (rustup update stable), then add the following to a Cargo config file. Use .cargo/config.toml in your project to share it with your team, or ~/.cargo/config.toml to apply it to every project on your machine:

TOML
[registry]
global-min-publish-age = "7 days"

The value is a number followed by a unit such as days. The default is "0", which allows every version. For registries other than crates.io , you can override the global value per registry:

TOML
[registries.my-registry]
min-publish-age = "3 days"

Like any Cargo config key, it can also be set with an environment variable, which is pretty handy in GitHub Actions: CARGO_REGISTRY_GLOBAL_MIN_PUBLISH_AGE="7 days".

What Cargo Holds Back

Dependency resolution happens in every Cargo command that needs the dependency graph, so cargo update, cargo build and friends all respect the cooldown. Two rules matter:

  • Versions that are younger than the configured age are ignored.
  • Versions that are already in your Cargo.lock are kept, no matter how young they are.

The second rule means turning the cooldown on does not downgrade anything. It only affects versions Cargo would newly pick. When a newer version exists but is still too young, Cargo tells you which one it skipped and how old it is.

Two exceptions are worth knowing. cargo install ignores the cooldown for the installed crate and its dependencies, so pin a version (cargo install [email protected]) if you care. And the check relies on the registry recording a pubtime for each version. Versions without one are never held back.

Override For A Security Fix

Sometimes the fresh release is exactly what you want, for example when a vulnerability in a dependency was just patched. The behavior is controlled by the resolver.incompatible-publish-age setting, which is deny by default. Set it to allow for a single command to force the update through:

BASH
CARGO_RESOLVER_INCOMPATIBLE_PUBLISH_AGE=allow cargo update -p foo

The updated version is recorded in Cargo.lock, and from then on the first rule applies: Cargo keeps it. Because the override is scoped to one command, your global cooldown stays in place for everything else.

If you need a specific version, combine it with --precise:

BASH
CARGO_RESOLVER_INCOMPATIBLE_PUBLISH_AGE=allow cargo update -p foo --precise 1.2.4

Use It In GitHub Actions

Commit your Cargo.lock and build with --locked. The lockfile is then the single source of truth, and the cooldown protects the moments where it changes: local cargo update runs or automated dependency update jobs. If those jobs run in GitHub Actions, set the environment variable there:

YAML
env:
  CARGO_REGISTRY_GLOBAL_MIN_PUBLISH_AGE: "7 days"

Spin And Wasm Projects

A Spin component written in Rust is a regular Cargo project, and spin build calls cargo build for you. A .cargo/config.toml next to the component’s Cargo.toml therefore protects Spin apps without any Spin-specific configuration. Spin and Wasm projects tend to pull in a fair number of crates, so this is a cheap safety net.

Recap

Set registry.global-min-publish-age once, let Cargo keep your lockfile entries as they are, and use CARGO_RESOLVER_INCOMPATIBLE_PUBLISH_AGE=allow when you deliberately want a fresh release. A cooldown is not a replacement for auditing dependencies, but it is a cheap first line of defense.