Answer#
Sometimes the fixed version needs a newer compiler, a breaking change in your own code, or does not exist (an abandoned crate). Silencing the tool is acceptable only as a decision with a record.
Work through these questions in order:
- Is there a fix? The advisory page lists patched versions.
cargo update -p <crate>may be enough. - Is the vulnerable crate pulled in by another crate?
cargo tree -i <crate>shows who depends on it; updating or replacing that parent may remove it. - Does your code reach the affected part? Advisories name the affected functions or platforms. The advisory behind the example below says that the problem only affects non-Windows targets.
- Can you remove the dependency, or use an alternative crate?
- If none of that is possible now: ignore it explicitly, with a reason and a review date.
Ignoring in deny.toml (the format of cargo-deny 0.20.2, as tested on the advisory from the cargo audit thread):
[advisories]
version = 2
ignore = [
{ id = "RUSTSEC-2020-0071", reason = "demo only: the affected function is not called, re-check by 2027-03-01" },
]With that file, cargo deny check advisories on the test project printed:
advisories okand without the ignore entry the same command reported error[vulnerability] with the advisory ID. The reason text is free text; the review date inside it is a convention that you must enforce yourself, for example with a calendar reminder or a CI step.
How to do it#
- Keep ignores in one file under version control, reviewed like code.
- Write why it does not apply, and who decided.
- Set a date to look again. Remove the entry as soon as a fix exists.
- Mention it in release notes if users could be affected.
Common mistakes#
- Ignoring by crate instead of by advisory ID: a later, different advisory for the same crate is then hidden.
- Leaving an ignore in place for years.
- Judging severity from the score alone. The context (what the code does with untrusted data) matters more.
Related questions#
Can I run the check without failing the build on warnings?#
Yes, cargo-deny lets you set the level (deny, warn, allow) for several categories in deny.toml. Keep vulnerabilities at deny.
Who should be allowed to add an ignore?#
Anyone through a pull request, but with a reviewer who is not the author. The file is a record of accepted risk.
Sources#
- cargo-deny book, advisories config: https://embarkstudios.github.io/cargo-deny/checks/advisories/cfg.html
- RustSec advisory RUSTSEC-2020-0071: https://rustsec.org/advisories/RUSTSEC-2020-0071.html