CVE-2023-40030: Cargo Malicious Dependencies Can Inject Arbitrary Vulnerability

LOW
Advisory Identifier: GHSA-wrrj-h57r-vx9p
CWE-79
Published
Advisory Summary

CVE-2023-40030 is a LOW malicious dependencies can inject arbitrary vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting Cargo libraries in the crates.io ecosystem. The issue involves malicious dependencies can inject arbitrary javascript into cargo-generated timing reports. Remediation is available by upgrading affected packages to version 1.72.

CVE-2023-40030 at a Glance

CVE Identifier CVE-2023-40030
GHSA Identifier GHSA-wrrj-h57r-vx9p
Severity LOW
CVSS v3.1 Base Score N/A
CWE Classification CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Affected Product Cargo
Package Ecosystem crates.io
Published Date
Last Updated

How to Fix CVE-2023-40030

To remediate this vulnerability, upgrade all affected Cargo dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

cargo fixed: 1.72
Upgrade cargo to 1.72
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for cargo

How to Check if You Are Affected

To determine whether your application is affected by CVE-2023-40030, inspect your project dependencies for Cargo:

inspect dependencies for cargo

Analyze the terminal output to locate any version of Cargo in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.72), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), where the product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. In Cargo, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

The Rust Security Response WG was notified that Cargo did not escape Cargo feature names when including them in the report generated by `cargo build --timings`. A malicious package included as a dependency may inject nearly arbitrary HTML here, potentially leading to XSS if the report is subsequently uploaded somewhere. The severity of this vulnerability is "low" for users relying on dependencies from git, local paths, or alternative registries. Users who solely depend on crates.io are unaffected. Note that **by design** Cargo allows code execution at build time, due to build scripts and procedural macros. The vulnerability in this advisory allows performing a subset of the possible damage in a harder to track down way. Your dependencies must still be trusted if you want to be protected from attacks, as it's possible to perform the same attacks with build scripts and procedural macros. # Overview Rust 1.60.0 [introduced](https://blog.rust-lang.org/2022/04/07/Rust-1.60.0.html#cargo---timings) `cargo build --timings`, which produces a report of how long the different steps of the build process took. It includes lists of Cargo features for each crate. Prior to Rust 1.72, Cargo feature names were allowed to contain almost any characters (with some exceptions as used by the feature syntax), but it would produce a future incompatibility warning about them [since Rust 1.49](https://github.com/rust-lang/cargo/pull/8814). crates.io is far more stringent about what it considers a valid feature name and has not allowed such feature names. As the feature names defined in the `Cargo.toml` file were included unescaped in the timings report, they could be used to inject Javascript into the page. For example with a feature name like `features = ["<img src='' onerror=alert(0)"]`. If this report were subsequently uploaded to a domain that uses credentials, the injected Javascript could access resources from the website visitor. This issue was fixed by [turning the future incompatibility warning into an error](https://github.com/rust-lang/cargo/pull/12291). # Affected versions The vulnerability is present in all versions of Cargo after and including 1.60.0. Rust 1.72, to be released on August 24, will include a fix for it. Users whose dependencies are entirely on crates.io are unaffected. # Mitigations We recommend users always excercise care in which package they download, by only including trusted dependencies in their projects. Please note that even with these vulnerabilities fixed, by design Cargo allows arbitrary code execution at build time thanks to build scripts and procedural macros: a malicious dependency will be able to cause damage regardless of these vulnerabilities. crates.io has server-side checks preventing this attack, and there are no packages on crates.io exploiting these vulnerabilities. crates.io users still need to excercise care in choosing their dependencies though, as remote code execution is allowed by design there as well.

CVE-2023-40030 Affected Cargo Versions

1 component(s)
Fixed Versions:
1.72
Product / Package Ecosystem Affected Versions Fixed Version
cargo
crates.io
≥ 1.60.0
< 1.72
1.72

References

Frequently Asked Questions

What is CVE-2023-40030?
CVE-2023-40030 is a security vulnerability in Cargo involving Malicious dependencies can inject arbitrary JavaScript into cargo-generated timing reports under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
Which Cargo versions are affected?
Affected versions include releases prior to 1.72 across affected packages: cargo.
What version fixes CVE-2023-40030?
Upgrading to 1.72 (or the latest patched release for your respective branch) resolves the vulnerability.
Is cargo affected?
Yes, cargo is affected in releases prior to 1.72. Upgrade your dependency to 1.72 or later.
What CWE is associated with CVE-2023-40030?
CVE-2023-40030 is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.).
How can I check crates.io dependencies for CVE-2023-40030?
Run the dependency tree command: 'inspect dependencies for cargo'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-wrrj-h57r-vx9p",
  "modified" : "2025-06-24T20:17:26Z",
  "published" : "2023-08-24T22:15:51Z",
  "aliases" : [ "CVE-2023-40030" ],
  "summary" : "Malicious dependencies can inject arbitrary JavaScript into cargo-generated timing reports",
  "details" : "The Rust Security Response WG was notified that Cargo did not escape Cargo feature names when including them in the report generated by `cargo build --timings`. A malicious package included as a dependency may inject nearly arbitrary HTML here, potentially leading to XSS if the report is subsequently uploaded somewhere.\n\nThe severity of this vulnerability is \"low\" for users relying on dependencies from git, local paths, or alternative registries. Users who solely depend on crates.io are unaffected.\n\n\nNote that **by design** Cargo allows code execution at build time, due to build scripts and procedural macros. The vulnerability in this advisory allows performing a subset of the possible damage in a harder to track down way. Your dependencies must still be trusted if you want to be protected from attacks, as it's possible to perform the same attacks with build scripts and procedural macros.\n\n# Overview\n\nRust 1.60.0 [introduced](https://blog.rust-lang.org/2022/04/07/Rust-1.60.0.html#cargo---timings) `cargo build --timings`, which produces a report of how long the different steps of the build process took. It includes lists of Cargo features for each crate.\n\nPrior to Rust 1.72, Cargo feature names were allowed to contain almost any characters (with some exceptions as used by the feature syntax), but it would produce a future incompatibility warning about them [since Rust 1.49](https://github.com/rust-lang/cargo/pull/8814). crates.io is far more stringent about what it considers a valid feature name and has not allowed such feature names.\n\nAs the feature names defined in the `Cargo.toml` file were included unescaped in the timings report, they could be used to inject Javascript into the page. For example with a feature name like `features = [\"<img src='' onerror=alert(0)\"]`. If this report were subsequently uploaded to a domain that uses credentials, the injected Javascript could access resources from the website visitor.\n\nThis issue was fixed by [turning the future incompatibility warning into an error](https://github.com/rust-lang/cargo/pull/12291).\n\n# Affected versions\n\nThe vulnerability is present in all versions of Cargo after and including 1.60.0. Rust 1.72, to be released on August 24, will include a fix for it.\n\nUsers whose dependencies are entirely on crates.io are unaffected.\n\n# Mitigations\n\nWe recommend users always excercise care in which package they download, by only including trusted dependencies in their projects. Please note that even with these vulnerabilities fixed, by design Cargo allows arbitrary code execution at build time thanks to build scripts and procedural macros: a malicious dependency will be able to cause damage regardless of these vulnerabilities.\n\ncrates.io has server-side checks preventing this attack, and there are no packages on crates.io exploiting these vulnerabilities. crates.io users still need to excercise care in choosing their dependencies though, as remote code execution is allowed by design there as well.",
  "severity" : [ ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "crates.io",
      "name" : "cargo"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "1.60.0"
      }, {
        "fixed" : "1.72"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/rust-lang/cargo/security/advisories/GHSA-wrrj-h57r-vx9p"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rust-lang/cargo/commit/9835622853f08be9a4b58ebe29dcec8f43b64b33"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rust-lang/cargo/commit/f975722a0eac934c0722f111f107c4ea2f5c4365"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/rust-lang/cargo"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-79" ],
    "severity" : "LOW",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-08-24T22:15:51Z",
    "nvd_published_at" : "2023-08-24T23:15:09Z"
  }
}