Skip to content

Commit 3605e0f

Browse files
authored
Merge pull request rust-lang#495 from tarcieri/inside-rust/cargo-audit-0.11
Inside Rust: Add cargo-audit 0.11 blog post
2 parents d18243c + 93e988f commit 3605e0f

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
layout: post
3+
title: "cargo-audit v0.11: Introducing the `fix` feature, yanked crate detection, and more"
4+
author: Tony Arcieri
5+
description: "Release announcement for cargo-audit v0.11 describing the new features"
6+
team: the Secure Code WG <https://www.rust-lang.org/governance/wgs/wg-secure-code>
7+
---
8+
9+
[cargo-audit](https://github.com/rustsec/cargo-audit) is a command-line utility which inspects `Cargo.lock` files and compares them against the [RustSec Advisory Database](https://rustsec.org), a community database of security vulnerabilities maintained by the [Rust Secure Code Working Group](https://github.com/rust-secure-code/wg).
10+
11+
This post describes the new features in the 0.11 release of `cargo-audit`.
12+
13+
## `cargo audit fix`: automatically update vulnerable dependencies
14+
15+
One of our [most requested features](https://github.com/RustSec/cargo-audit/issues/23) (especially by fans of the similar [`npm audit fix`](https://docs.npmjs.com/cli/audit) command), the [new `cargo audit fix` subcommand](https://github.com/RustSec/cargo-audit#cargo-audit-fix-subcommand) will attempt to automatically update version requirements for vulnerable dependencies to non-vulnerable versions.
16+
17+
Note that this is an experimental new feature which isn't enabled by default. To try it out, install `cargo-audit with the following.
18+
19+
You can install `cargo-audit` and run it against your project with the following commands:
20+
21+
```
22+
$ cargo install cargo-audit --features=fix
23+
```
24+
25+
This will perform the same audit process as `cargo audit` initially, and then attempt to apply fixes to your `Cargo.toml`:
26+
27+
![cargo audit fix screenshot](https://raw.githubusercontent.com/RustSec/cargo-audit/c857beb/img/screenshot-fix.png)
28+
29+
Under the hood, it uses [cargo-edit](https://github.com/killercup/cargo-edit) (as a library) to perform modifications to your `Cargo.toml` file, using the fixed version requirements listed in the advisory to try to perform an automatic upgrade to a non-vulnerable version of a dependency for each advisory.
30+
31+
Note once more that this is a *new, experimental feature* and as such it's bound to have bugs. If you're worried, you can use `cargo audit fix --dry-run` to perform a dry run only. And if you do encounter bugs, please [file a bug report](https://github.com/rustsec/cargo-audit/issues).
32+
33+
We'd like to thank Reza Fatahi and Hanif Ariffin for their work in contributing this feature.
34+
35+
## Warnings for yanked crates
36+
37+
As you can see in the screenshot above, `cargo audit` now checks each of the crates in your `Cargo.lock` file against the [crates.io](https://crates.io) index to determine if any of them have been yanked. If they have, it will emit a warning as per above.
38+
39+
If you'd like for yanked crates to be a hard failure, you can run `cargo audit` with the `-D` command-line argument:
40+
41+
```
42+
$ cargo audit -D
43+
```
44+
45+
or if you prefer to be more explicit:
46+
47+
```
48+
$ cargo audit --deny-warnings
49+
```
50+
51+
## Compatibility with the new "V2" format for `Cargo.lock`
52+
53+
Rust 1.39 shipped support for a new [merge-friendly `Cargo.lock` format](https://github.com/rust-lang/cargo/pull/7070).
54+
55+
`cargo audit` consumes `Cargo.lock` directly, and while the V2 format change didn't break the core vulnerability-auditing functionality of `cargo audit`, several minor features regressed because of this, such as displaying dependency trees for vulnerable dependencies.
56+
57+
This release also upgrades to version 4.0 of the [`cargo-lock` crate](https://github.com/RustSec/cargo-lock), which includes full support for the V2 `Cargo.lock` format and constructs a representation of a lockfile which is the same across the V1 and V2 formats.
58+
59+
If you noticed dependency trees failing to display after upgrading to the V2 `Cargo.lock` format, they should now be working again!
60+
61+
Thanks for reading, and we hope you enjoy `cargo-audit` 0.11!
62+

0 commit comments

Comments
 (0)