Guides / Languages and packages

Audit Rust crates with cargo audit

intermediateUpdated 26 Nov 2026939 words

cargo audit checks the Cargo.lock of a Rust project against the RustSec Advisory Database. It reports crates with vulnerabilities and, as warnings, crates that are unmaintained, unsound or yanked from crates.io. The RustSec project maintains both the tool and the database.

Install it

The RustSec project publishes prebuilt binaries for Linux, macOS and Windows on GitHub (version 0.23.0 in November 2026). For x86_64 Linux:

curl -fsSLO https://github.com/rustsec/rustsec/releases/download/cargo-audit%2Fv0.23.0/cargo-audit-x86_64-unknown-linux-musl-v0.23.0.tgz
tar -xzf cargo-audit-x86_64-unknown-linux-musl-v0.23.0.tgz
install -m 755 cargo-audit-x86_64-unknown-linux-musl-v0.23.0/cargo-audit ~/.cargo/bin/

cargo install cargo-audit --locked builds it from source with all its dependencies. Alpine (apk add cargo-audit), Arch Linux and Homebrew also package it.

Run it

From the workspace root:

cargo audit

For a project with smallvec 1.6.0 and time 0.1.43 in Cargo.lock (cargo-audit 0.23.0):

    Fetching advisory database from `https://github.com/RustSec/advisory-db.git`
      Loaded 1568 security advisories (from /usr/local/cargo/advisory-db)
    Scanning Cargo.lock for vulnerabilities (7 crate dependencies)
Crate:     smallvec
Version:   1.6.0
Title:     Buffer overflow in SmallVec::insert_many
Date:      2021-01-08
ID:        RUSTSEC-2021-0003
URL:       https://rustsec.org/advisories/RUSTSEC-2021-0003
Severity:  9.8 (critical)
Solution:  Upgrade to >=0.6.14, <1.0.0 OR >=1.6.1 (patched)

Crate:     time
Version:   0.1.43
Title:     Potential segfault in the time crate
Date:      2020-11-18
ID:        RUSTSEC-2020-0071
URL:       https://rustsec.org/advisories/RUSTSEC-2020-0071
Severity:  6.2 (medium)
Solution:  Upgrade to >=0.2.23 (patched)

error: 2 vulnerabilities found!

The advisory page lists the CVE and GHSA aliases.

The exit code is 1 when cargo audit finds a vulnerability. Warnings do not change it; --deny warnings (or -D unmaintained, -D unsound, -D yanked) makes them fail the run too.

If Cargo.lock is missing, cargo audit runs cargo update to create one. For a library without a committed lockfile the result then shows the newest matching versions, which may differ from what a user of the library builds with. Commit Cargo.lock for every binary you deploy.

The cargo-audit README advises to run it only on projects you trust. For a project you do not trust, pass the lockfile with --file and run it from a directory outside the project:

cd /tmp && cargo audit --file /path/to/project/Cargo.lock

Fix findings

For a fix within the same semver range, run cargo update:

cargo update -p smallvec
cargo audit
    Updating smallvec v1.6.0 -> v1.16.6

If the fix is in a newer major line (time 0.1 to 0.2.23 or later in the example; the current line is 0.3), change the requirement in Cargo.toml and adapt the code. When the vulnerable crate is not your direct dependency, find out which crate pulls it in:

cargo tree -i time
time v0.1.43
└── audit-demo v0.1.0 (/src)

In the example it is a direct dependency; in a real project the tree usually shows a chain of crates. Update the crate in the middle, or open an issue upstream if it still requires the vulnerable version.

Ignore an advisory

For an advisory that does not affect you, for example one for a platform you do not build for, add it to .cargo/audit.toml in the project:

[advisories]
ignore = ["RUSTSEC-2020-0071"]

In the example, the next run reported only RUSTSEC-2021-0003. On the command line, --ignore RUSTSEC-2020-0071 does the same. Write the reason next to it.

Audit release binaries

A binary on a server does not carry its Cargo.lock. cargo auditable embeds the dependency list in the binary at build time, and cargo audit bin checks it later without the source. Install the cargo subcommand with cargo install cargo-auditable --locked or from the binaries on its GitHub releases page (version 0.7.8 in November 2026), then build with it:

cargo auditable build --release
cargo audit bin target/release/audit-demo
       Found 'cargo auditable' data in target/release/audit-demo (4 dependencies)
Crate:     smallvec
Version:   1.6.0
...
error: 2 vulnerabilities found in target/release/audit-demo

The same program built with plain cargo build:

warning: target/release/audit-demo was not built with 'cargo auditable', the report will be incomplete (1 dependencies recovered)
...
error: 1 vulnerability found in target/release/audit-demo

Without the embedded data, cargo audit recovers part of the dependency list from panic messages in the binary; here it missed smallvec.

Run it in CI

The RustSec GitHub Action fails a push or pull request with an advisory, and on scheduled runs opens one issue per new advisory:

name: cargo audit
on:
  push:
    paths:
      - "**/Cargo.toml"
      - "**/Cargo.lock"
  schedule:
    - cron: "7 6 * * *"
jobs:
  audit:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      issues: write
      checks: write
    steps:
      - uses: actions/checkout@v7
      - uses: rustsec/audit-check@v2.0.0
        with:
          token: ${{ secrets.GITHUB_TOKEN }}

In GitLab CI, use the binary release in the Rust image of your build. Started outside cargo, the binary expects audit as its first argument:

cargo-audit:
  image: rust:1.99.1-bookworm
  script:
    - curl -fsSL https://github.com/rustsec/rustsec/releases/download/cargo-audit%2Fv0.23.0/cargo-audit-x86_64-unknown-linux-musl-v0.23.0.tgz | tar -xz
    - ./cargo-audit-x86_64-unknown-linux-musl-v0.23.0/cargo-audit audit --deny warnings

cargo deny check advisories, from the cargo-deny tool, reads the same database. cargo-deny also checks licences and duplicate crates.

What it does not cover

cargo audit knows Rust crates. C libraries that a crate links to dynamically (OpenSSL through openssl-sys, for example) come from the operating system or the container image and get their updates there. Crates that vendor a C library get fixes as new crate releases, and the database has entries for them (openssl-src, for example).

The Vulnpocalypse agent reads the Cargo.lock of the app paths you configure, and Vulnpocalypse checks it against new advisories every day.

Sources

Check your servers every day

The Vulnpocalypse agent reports the packages and settings of a server once a day, and the digest lists what to fix, most urgent first.

Start free