|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Security advisory for Cargo" |
| 4 | +author: The Rust Security Team |
| 5 | +--- |
| 6 | + |
| 7 | +> **Note**: This is a cross-post of the [official security advisory]. The official |
| 8 | +> post contains a signed version with our PGP key, as well. |
| 9 | +
|
| 10 | +The Rust team was recently notified of a security concern when using older versions of Cargo to build crates which use the package rename feature added in newer versions of Cargo. If you're using Rust 1.26.0, released on 2018-05-10, or later you're not affected. |
| 11 | + |
| 12 | +The CVE for this vulnerability is [CVE-2019-16760][0]. |
| 13 | + |
| 14 | +## Overview |
| 15 | + |
| 16 | +Cargo can be configured through `Cargo.toml` and the `[dependencies]` section to depend on different crates, such as those from crates.io. There are multiple ways to configure how you depend on crates as well, for example if you depend on `serde` and enable the `derive` feature it would look like: |
| 17 | + |
| 18 | +```toml |
| 19 | +serde = { version = "1.0", features = ['derive'] } |
| 20 | +``` |
| 21 | + |
| 22 | +Rust 1.31.0 [introduced a new feature of Cargo][1] where one of the optional keys you can specify in this map is `package`, a way to [rename a crate locally][2]. For example if you preferred to use `serde1` locally instead of `serde`, you could write: |
| 23 | + |
| 24 | +```toml |
| 25 | +serde1 = { version = "1.0", features = ['derive'], package = "serde" } |
| 26 | +``` |
| 27 | + |
| 28 | +It's the addition of the `package` key that causes Cargo to compile the crate differently. This feature was [first implemented][3] in Rust 1.26.0, but it was unstable at the time. For Rust 1.25.0 and prior, however, Cargo would ignore the `package` key and and interpret the dependency line as if it were: |
| 29 | + |
| 30 | +```toml |
| 31 | +serde1 = { version = "1.0", features = ['derive'] } |
| 32 | +``` |
| 33 | + |
| 34 | +This means when compiled with Rust 1.25.0 and prior then it would attempt to download the `serde1` crate. A malicious user could squat the `serde1` name on crates.io to look like `serde 1.0.0` but instead act maliciously when built. |
| 35 | + |
| 36 | +In summary, usage of the `package` key to rename dependencies in `Cargo.toml` is ignored in Rust 1.25.0 and prior. When Rust 1.25.0 and prior is used Cargo will ignore `package` and download the wrong dependency, which could be squatted on crates.io to be a malicious package. This not only affects manifests that you write locally yourself, but also manifests published to crates.io. If you published a crate, for example, that depends on `serde1` to crates.io then users who depend on you may also be vulnerable if they use Rust 1.25.0 and prior. |
| 37 | + |
| 38 | +## Affected Versions |
| 39 | + |
| 40 | +Rust 1.0.0 through Rust 1.25.0 is affected by this advisory because Cargo will ignore the `package` key in manifests. Rust 1.26.0 through Rust 1.30.0 are not affected and typically will emit an error because the `package` key is unstable. Rust 1.31.0 and after are not affected because Cargo understands the `package` key. |
| 41 | + |
| 42 | +In terms of Cargo versions, this affects Cargo up through Cargo 0.26.0. All future versions of Cargo are unaffected. |
| 43 | + |
| 44 | +## Mitigations |
| 45 | + |
| 46 | +We strongly recommend that users of the affected versions update their compiler to the latest available one. Preventing this issue from happening requires updating your compiler to either Rust 1.26.0 or newer. |
| 47 | + |
| 48 | +We will not be issuing a patch release for Rust versions prior to 1.26.0. Users of Rust 1.19.0 to Rust 1.25.0 can instead apply [the provided patches][4] to mitigate the issue. |
| 49 | + |
| 50 | +An audit of existing crates published to crates.io using the `package` key has been performed and there is no evidence that this vulnerability has been exploited in the wild. Our audit only covers the crates currently published on crates.io: if you notice crates exploiting this vulnerability in the future please don't hesitate to email [email protected] in accordance with [our security policy ][5]. |
| 51 | + |
| 52 | +## Timeline of events |
| 53 | + |
| 54 | +* Wed, Sep 18, 2019 at 13:54 UTC - Bug reported to [email protected] |
| 55 | +* Wed, Sep 18, 2019 at 15:35 UTC - Response confirming the report |
| 56 | +* Wed, Sep 18, 2019 - Cargo, Core, and crates.io teams confer on how best to handle this |
| 57 | +* Thu, Sep 19, 2019 - Confirmed with Elichai plan of action and continued to audit existing crates |
| 58 | +* Mon, Sep 23, 2019 - Advisory drafted, patches developed, audit completed |
| 59 | +* Mon, Sep 30, 2019 - Advisory published, security list informed of this issue |
| 60 | + |
| 61 | +## Acknowledgments |
| 62 | + |
| 63 | +Thanks to Elichai Turkel, who found this bug and reported it to us in accordance |
| 64 | +with our [security policy][5]. |
| 65 | + |
| 66 | +[0]: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2019-16760 |
| 67 | +[1]: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html#cargo-features |
| 68 | +[2]: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#renaming-dependencies-in-cargotoml |
| 69 | +[3]: https://github.com/rust-lang/cargo/pull/4953 |
| 70 | +[4]: https://gist.github.com/pietroalbini/0d293b24a44babbeb6187e06eebd4992 |
| 71 | +[5]: https://www.rust-lang.org/policies/security |
| 72 | +[official security advisory]: https://groups.google.com/forum/#!topic/rustlang-security-announcements/rVQ5e3TDnpQ |
0 commit comments