Guides / Languages and packages

Audit Rust crates with cargo audit

intermediateUpdated 26 Nov 20261003 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. It comes from the RustSec project, which also maintains the database.

Install it

The RustSec project publishes prebuilt binaries for Linux, macOS and Windows on GitHub (as of November 2026, version 0.23.0). 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/

Or build it from source with cargo install cargo-audit --locked, which compiles it 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!

Each vulnerability has a RustSec ID, the version in your lockfile, a CVSS score where the advisory has one, and the versions with the fix. The advisory page has the CVE and GHSA aliases. Advisories of the kinds unmaintained and unsound, and crates yanked from crates.io, appear as warnings.

The exit code is 1 when a vulnerability is found. 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 versions that match, not 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

A semver-compatible fix is one cargo update away:

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 who pulls it in:

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

Here it is a direct dependency; in a real project the tree usually shows a chain of crates.

Then update the crate in the middle, or open an issue upstream if it has not moved to the fixed version yet.

Ignore an advisory

For an advisory that does not affect you, for example 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.

The same works on the command line with --ignore RUSTSEC-2020-0071. Write the reason next to it.

Audit release binaries

A binary on a server does not carry its Cargo.lock. If you build it with cargo auditable, the dependency list is embedded in the binary and cargo audit bin can check it later, without the source. cargo auditable is a cargo subcommand; install it with cargo install cargo-auditable --locked or from the binaries on its GitHub releases page (version 0.7.8 as of 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. The binary expects audit as its first argument when it is not started through cargo:

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 and fits teams that also check 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 need their own updates; crates that vendor a C library get fixes as new crate releases, and the database has entries for them (openssl-src, for example).

The Patchbrief agent can read the Cargo.lock of the app paths you configure and checks it against new advisories every day.

Sources

Check your servers every day

The agent of Patchbrief reports the packages and settings of a server once a day; the digest names what to fix first.

Start free