|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Keeping Rust projects secure with cargo-audit 0.18: performance, compatibility and security improvements" |
| 4 | +author: Sergey "Shnatsel" Davidoff |
| 5 | +description: "A look at the new features in cargo-audit 0.18 for ensuring dependencies are free of known vulnerabilities" |
| 6 | +team: the Secure Code WG <https://www.rust-lang.org/governance/wgs/wg-secure-code> |
| 7 | +--- |
| 8 | + |
| 9 | +[`cargo audit`](https://crates.io/crates/cargo-audit) checks your project's dependencies for known security vulnerabilites. |
| 10 | + |
| 11 | +By default `cargo audit` checks on your `Cargo.lock` file, but it can also [scan compiled binaries](https://github.com/rustsec/rustsec/tree/main/cargo-audit#cargo-audit-bin-subcommand). You can install `cargo-audit` and run it against your project with the following commands: |
| 12 | + |
| 13 | +``` |
| 14 | +$ cargo install cargo-audit |
| 15 | +$ cargo audit |
| 16 | +``` |
| 17 | + |
| 18 | +Both `cargo audit` and the [RustSec](https://rustsec.org/) advisory database that powers it are maintained by the [Rust Secure Code working group](https://www.rust-lang.org/governance/wgs/wg-secure-code). |
| 19 | + |
| 20 | +## What's new in this release |
| 21 | + |
| 22 | +### Performance |
| 23 | + |
| 24 | +`cargo audit` now uses the [sparse crates.io index](https://blog.rust-lang.org/inside-rust/2023/01/30/cargo-sparse-protocol.html) when checking for yanked crates. This dramatically speeds up the scanning process because `cargo audit` no longer needs to download the entire crates.io index, which could take up to several minutes. |
| 25 | + |
| 26 | +Sparse index is used by default if you are running Rust 1.70 or later, same as in Cargo itself. `cargo audit` honors [the Cargo settings for the use of sparse index](https://doc.rust-lang.org/cargo/reference/config.html#registriescrates-ioprotocol), should you need to opt out for any reason. |
| 27 | + |
| 28 | +### Security |
| 29 | + |
| 30 | +`cargo audit` previously relied on [OpenSSL](https://en.wikipedia.org/wiki/OpenSSL) on all platforms. In this release we have switched to [rustls](https://crates.io/crates/rustls) - a high-quality, memory-safe TLS implementation in Rust. |
| 31 | + |
| 32 | +In contrast to OpenSSL's [history](https://www.openssl.org/news/vulnerabilities.html) of high-severity vulnerabilities, rustls has a stellar track record and eliminates entire classes vulnerabilities by construction. It has passed an independent audit with flying colors; the auditors even [noted](https://github.com/rustls/rustls/blob/main/audit/TLS-01-report.pdf) that they "had the rare pleasure of being impressed with the exceptional quality of the presented software". |
| 33 | + |
| 34 | +Since TLS constitutes the vast majority of the attack surface of `cargo audit`, we are very excited to use a more secure TLS implementation! |
| 35 | + |
| 36 | +### Compatibility |
| 37 | + |
| 38 | +A number of long-standing issues are resolved thanks to switching from [libgit2](https://github.com/libgit2/libgit2) to [gitoxide](https://github.com/Byron/gitoxide) as our git implementation: |
| 39 | + |
| 40 | + 1. [`cargo audit` can now run in Alpine Linux containers](https://github.com/rustsec/rustsec/issues/466). |
| 41 | + 1. [Several instances of `cargo audit` running in parallel can now fetch Git repositories without issue](https://github.com/rustsec/rustsec/issues/490). |
| 42 | + 4. [Accessing Git repositories over SSH is now supported](https://github.com/rustsec/rustsec/issues/292). |
| 43 | + 3. [Credential helpers to access private repositories are now supported](https://github.com/rustsec/rustsec/issues/555). |
| 44 | + |
| 45 | +## Known issues |
| 46 | + |
| 47 | +### Limited CPU architecture support |
| 48 | + |
| 49 | +CPU architectures other than x86 and ARM are not supported by this release. This is due to [ring](https://github.com/briansmith/ring), the cryptographic library used by rustls, not supporting other CPU architectures yet. |
| 50 | + |
| 51 | +rustls is [in the process](https://github.com/rustls/rustls/issues/521) of adding support for other cryptographic libraries. We will consider adding support for another TLS implementation if no portable cryptographic library for rustls materializes in the near future. |
| 52 | + |
| 53 | +In the meantime we recommend using the previous release on uncommon CPU architectures. You may also consider other tools that read `Cargo.lock` files and the RustSec advisory database, such as [Trivy](https://github.com/aquasecurity/trivy), [osv-scanner](https://github.com/google/osv-scanner) or [Dependabot](https://docs.github.com/en/code-security/dependabot/dependabot-alerts/about-dependabot-alerts). |
| 54 | + |
| 55 | +### `cargo audit fix` is not converted |
| 56 | + |
| 57 | +The experimental subcommand `cargo audit fix` to automatically upgrade vulnerable dependencies has existed for a while but has been disabled by default. It has **not** been converted to use gitoxide and rustls in this release, and has not benefited from any of these improvements. |
| 58 | + |
| 59 | +We will likely [rewrite this feature from the ground up](https://github.com/rustsec/rustsec/issues/938) before enabling it by default in subsequent releases. |
| 60 | + |
| 61 | +## Reporting issues |
| 62 | + |
| 63 | +Due to the sweeping changes to the libraries `cargo audit` relies on for git protocol and networking there are bound to be subtle differences in behavior compared to previous versions. |
| 64 | + |
| 65 | +If you encounter issues with this latest release, please [report it to us on Github](https://github.com/rustsec/rustsec/issues/new). Thank you! |
| 66 | + |
| 67 | +## Acknowledgements |
| 68 | + |
| 69 | +Thanks to [Jake Shadle](https://github.com/Jake-Shadle) who did most of the work in this release, as well as for creating the [`tame-index`](https://github.com/EmbarkStudios/tame-index) crate that enabled sparse registry support in `cargo audit`. |
| 70 | + |
| 71 | +Thanks to [Sebastian Thiel](https://github.com/Byron) for creating [`gitoxide`](https://github.com/Byron/gitoxide) and improving it to accommodate the `cargo audit` requirements, as well as helping review the changes. |
0 commit comments