Safeguard
Supply Chain•

How do I fix a vulnerable Rust crate with cargo update?

Run a conservative cargo update on the crate, or set an exact version with the precise option, then commit Cargo.lock. Steps, limits and a check for yanks.

Safeguard Security Team
3 min read

To fix a vulnerable Rust crate, run cargo update with the crate name so Cargo moves only that crate and what it needs. If you need a specific fixed version, add the precise option. Cargo.toml requirements still limit the range, so a fix outside that range needs a manifest edit.

What cargo update changes

The Cargo documentation says the command updates dependencies in Cargo.lock to the latest version allowed. With no argument it updates everything. With a crate name it performs a conservative update: only that crate is updated, its own dependencies only if needed, and everything else stays at its recorded version.

Cargo.toml describes your dependencies in a broad sense. Cargo.lock holds the exact versions and is maintained by Cargo. The Cargo book advises checking Cargo.lock into version control when in doubt.

Steps

  1. Read the advisory for the fixed version.
  2. Preview the change:
cargo update vulnerable-crate --dry-run
  1. Apply it, either to the latest allowed version or to a chosen one:
cargo update vulnerable-crate
cargo update vulnerable-crate --precise 1.2.7
  1. Rebuild, run tests, and commit the Cargo.lock diff.
  2. Re-run your advisory scan.

The dry run option shows what would change without writing the lockfile.

When the precise option helps

Use it to land on the first fixed version rather than the newest one, which keeps the diff small. The documentation says it works on a named crate, can take a git revision for git sources, cannot be combined with the recursive option, and that yanked versions are allowed but not recommended.

When it does not work

SymptomLikely causeWhat to do
Cargo will not move to the fixed versionCargo.toml requirement excludes itEdit the requirement in the crate that declares it
The crate is a dependency of a dependencyA parent pins an old rangeUpdate the parent, or ask its maintainers
Fixed version is yankedThe author withdrew itChoose another fixed release

Cargo.toml requirements set the range of allowed versions, and the update picks versions inside that range.

Keep CI honest

Use the locked option in CI so a run fails if Cargo.lock would change. The update command documentation describes it as erroring if the lock file is missing or would change.

cargo build --locked

Quick check

Does cargo update edit Cargo.toml?

The Cargo docs describe it as rewriting Cargo.lock. Version requirements in Cargo.toml set the allowed range and are only changed by a separate, nightly-only breaking option.

Should a library commit Cargo.lock?

The Cargo book says to commit it when in doubt. Libraries are a special case, covered in our guide on committing Cargo.lock for a library.

Safeguard's dependency scanning reads your project files and flags known advisories, and its fix pull requests (off by default, all categories on Manual) keep a person in control. The free scan is a quick first look.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.