# What does cargo deny check, and how do I configure it?
Source: https://ruststudio.org/community/t/102/what-does-cargo-deny-check-and-how-do-i-configure-it
Author: Ruststudio Team (staff) | Published: 2026-12-05 | Updated: 2026-12-05 | Checked with: cargo-deny 0.20.2, rustc 1.93.0, Windows 11
Category: Help and questions | Kind: FAQ | Tags: security, cargo-deny, supply-chain, licences | Views: 0

## Short answer
cargo-deny applies four checks from a deny.toml file: advisories (RustSec), licenses (an allow-list), bans (crates or duplicate versions you refuse) and sources (approved registries and Git hosts). Run it in CI beside cargo audit. A new project must set its allowed licences before it passes.

## Answer
## Answer
`cargo audit` answers one question: "does a dependency have a known advisory?". `cargo deny` is a policy tool that asks four:

| Check | Question |
|---|---|
| `advisories` | Are there vulnerabilities, unmaintained crates or yanked versions (the RustSec database)? |
| `licenses` | Is every dependency under a licence you allow? |
| `bans` | Is a crate that you refuse in the graph, or are there several versions of the same crate? |
| `sources` | Does every crate come from a registry or repository you approved? |

Start with `cargo deny init`, which writes a commented `deny.toml`, then edit it. This is a small file that works for a project whose dependencies are MIT or Apache-2.0:

```toml title=deny.toml
[advisories]
version = 2

[licenses]
allow = ["MIT", "Apache-2.0"]

[bans]
multiple-versions = "warn"
wildcards = "deny"

[sources]
unknown-registry = "deny"
unknown-git = "deny"
```

Then run the checks. `cargo deny check` prints one line per area when everything passes:

```text
advisories ok, bans ok, licenses ok, sources ok
```

When a licence is not on the allow-list, the check fails and names the crate and the licence. That is what happened with a freshly created `deny.toml` in the test project: the default list is empty, so the first run rejected the crates until the allow-list was filled in. The project's own `Cargo.toml` also needs a `license` field, or the check reports the project as unlicensed.

## How to do it
1. Install with `cargo install cargo-deny --locked`.
2. Run `cargo deny init`, then set `licenses.allow` to the licences your legal policy accepts.
3. Set `sources` so only crates.io (and any Git host you name) is allowed. That stops a pasted Git dependency from slipping in.
4. Use `bans` to forbid crates you have decided against, and to see duplicate versions of one crate (`multiple-versions = "warn"`).
5. Run `cargo deny check` in CI. Use `cargo deny check advisories` as a separate, scheduled job, because advisories change without code changes.

## Common mistakes
- Copying a long allow-list without reading it. Each licence is a decision.
- Turning every warning into an ignore entry. See the thread on handling advisories.
- Running it only on developer machines.

## Related questions
### Do I need both cargo audit and cargo deny?
`cargo deny check advisories` reads the same database as `cargo audit`, so it can replace it. Many teams use `cargo deny` alone for all four areas.

### Where do I run it in CI?
As a separate step after the build, with `cargo deny check`. Run the advisories check on a schedule too, since new advisories appear without code changes.

## Sources
- cargo-deny book: https://embarkstudios.github.io/cargo-deny/
- cargo-deny, checks: https://embarkstudios.github.io/cargo-deny/checks/index.html
- SPDX licence list: https://spdx.org/licenses/
