skip to content

What does `cargo audit` check in a Rust project, and which of its findings fail the command by default?

level: middleimportance: should knowfreq 35%

answer

  1. it reads a file, not your source
  2. the RustSec advisory database
  3. vulnerabilities versus informational warnings
  4. exit 1 versus exit 0
  5. --deny and --ignore

basics

~10 s

cargo audit matches every package version in Cargo.lock against the RustSec advisory database. By default only a vulnerability advisory makes it exit 1; unmaintained, unsound and yanked findings are warnings unless you pass --deny.

solid answer

~40 s

`cargo audit` reads `Cargo.lock` (running `cargo update --workspace` to create one if it is missing) and compares each locked package version with the RustSec advisory database, a git repository it clones to `~/.cargo/advisory-db` and fetches on every run. A **vulnerability** advisory matching a locked version makes it exit with status 1. Informational advisories (`unmaintained`, `unsound`, `notice`) and **yanked** versions are printed as warnings and still exit 0, unless you pass `--deny warnings` or a single kind such as `-D unmaintained`. An advisory that does not affect you is silenced with `--ignore RUSTSEC-YYYY-NNNN` or the `ignore` list in `.cargo/audit.toml`. It refuses a database with no commits for 90 days unless you pass `--stale`, and exits 2 on errors.

go deeper

for a junior

Recall that cargo audit compares Cargo.lock with the RustSec advisory database and fails when a locked version has a vulnerability.

for a middle

Explain the split between vulnerabilities, which exit 1, and the unmaintained, unsound, notice and yanked warnings, plus --deny, --ignore and audit.toml.

for a senior

Show you know a match is version-based, not reachability, that the database is fetched each run, and how to record an exception with a reason.

for a principal

Weigh failing every pull request on a newly published advisory against a scheduled audit plus a gate on lockfile changes, and who owns ignores.

## What `cargo audit` is `cargo audit` is the RustSec project's subcommand (crate `cargo-audit`, current release 0.22.2) that answers one question: **does any crate version locked for this project have a published security advisory?** It is installed like any third-party subcommand, with `cargo install cargo-audit`, and run at the top of a Cargo project or workspace. ## The two inputs 1. **`Cargo.lock`.** The tool audits the *resolved* dependency graph, the exact `name` and `version` entries in the lockfile, not the version requirements in `Cargo.toml` and not your source code. If there is no `Cargo.lock` but there is a `Cargo.toml`, it runs `cargo update --workspace` to generate one first, which resolves to the newest versions the requirements allow. `-f PATH` audits another lockfile (or `-` for standard input). 2. **The RustSec advisory database**, a git repository of advisories identified as `RUSTSEC-YYYY-NNNN`. By default it is cloned into `~/.cargo/advisory-db` and **fetched before every audit**; `-n`/`--no-fetch` skips the fetch. A database with no commits for 90 days counts as stale and is refused unless you pass `--stale`. Each advisory names the affected crate and its patched version ranges, so the report says which locked version is affected and which upgrade fixes it (or "No fixed upgrade is available!"), with an inverse dependency tree showing how the crate got into your build. ## What fails the run `cargo audit` sorts its findings into two kinds: | Finding | Default outcome | Made fatal by | |---|---|---| | Vulnerability advisory | error, exit status 1 | always fatal unless ignored | | `unmaintained` advisory | warning, exit 0 | `-D unmaintained` or `-D warnings` | | `unsound` advisory | warning, exit 0 | `-D unsound` or `-D warnings` | | `notice` advisory | warning, exit 0 | `-D warnings` | | Yanked version in `Cargo.lock` | warning, exit 0 | `-D yanked` or `-D warnings` | The source is plain about it: the run fails when a vulnerability is found or when any warning kind listed under `--deny` was reported; otherwise it exits 0. An error in processing, such as a lockfile it cannot generate, exits 2. The same settings can live in a config file, `.cargo/audit.toml` in the project or `~/.cargo/audit.toml`, with `[output] deny = [...]` and `[advisories] ignore = [...]`. ## Ignoring an advisory The README's first advice is to upgrade the vulnerable crate, usually with `cargo update -p NAME` within the existing requirement. When no fix exists and the advisory cannot affect you, for example because it concerns a feature or API you never use, ignore it explicitly: - `cargo audit --ignore RUSTSEC-2017-0001` for one run; - `ignore = ["RUSTSEC-2017-0001"]` under `[advisories]` in `.cargo/audit.toml` so the decision is reviewed and versioned with the code. There are also filters that narrow what counts: `--target-os` and `--target-arch` (or the `[target]` table) drop advisories that only apply to other platforms, and `severity_threshold` ignores advisories below a CVSS severity. ## What it does not tell you - **Reachability.** A match means the vulnerable *version* is locked, not that your code calls the vulnerable function. Unless the target filters above are set, every package in the lockfile counts, including dev-dependencies and crates only built for another platform. - **Licences, bans or sources.** Those are cargo-deny's checks; cargo-deny also reads the same RustSec database for its advisories check. - **Undisclosed problems.** The database only knows what has been reported to it. ## Related modes - `cargo audit fix` (built with the `fix` feature) rewrites `Cargo.toml` requirements to patched versions; it is marked experimental. - `cargo audit bin PATH` audits compiled binaries. It is exact for binaries built with `cargo auditable`, which embeds the dependency list, and only partial otherwise. ## Why the defaults matter in CI Because the database is fetched on every run, the same commit can pass today and fail tomorrow when a new advisory lands. That is the point of the tool and also why teams decide deliberately whether a failing audit blocks every pull request or only those that change `Cargo.lock`. Two practical details follow from the same design: a CI job that caches the database and passes `--no-fetch` must still refresh it often enough not to trip the 90-day staleness check, and the tool itself should be installed at a pinned version so a new release does not change what fails without review.

  • Why can `cargo audit` fail on a commit that passed yesterday?
    It fetches the RustSec advisory database before every run, so a new advisory published overnight against a version already in `Cargo.lock` turns the same lockfile from clean into exit status 1. Nothing in the repository changed; the database did.
  • How do you record a justified exception rather than passing `--ignore` in a CI script?
    Put the advisory ID in the `ignore` list under `[advisories]` in the project's `.cargo/audit.toml`. The exception is then reviewed in a pull request and lives with the code, and the comment beside it can say why the advisory does not apply and when to revisit it.

  • cargo audit scans the Rust source for calls to vulnerable functions
  • cargo audit checks the version requirements written in Cargo.toml
  • An unmaintained crate makes cargo audit fail by default
  • A passing cargo audit means no dependency has a known problem of any kind
  • cargo audit works offline from a database bundled with the binary