# CVE-2023-40030: Malicious dependencies can inject arbitrary JavaScript into cargo-generated timing reports

> Malicious dependencies can inject JavaScript into Cargo timing reports, potentially leading to XSS if the report is uploaded to a web server.

- **Severity:** Medium 6.1 (`CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 24 Aug 2023
- **Updated:** 30 Sep 2024
- **Also known as:** AZL-28511, BELL-CVE-2023-40030, DEBIAN-CVE-2023-40030, GHSA-wrrj-h57r-vx9p, SUSE-SU-2023:3722-1, UBUNTU-CVE-2023-40030, openSUSE-SU-2024:13262-1

## What is CVE-2023-40030?

CVE-2023-40030 is a medium-severity cross-site scripting vulnerability in rust-lang cargo, published on 24 Aug 2023. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.

### Official description

Cargo downloads a Rust project’s dependencies and compiles the project. Starting in Rust 1.60.0 and prior to 1.72, 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 cross-site scripting if the report is subsequently uploaded somewhere. The vulnerability affects users relying on dependencies from git, local paths, or alternative registries. Users who solely depend on crates.io are unaffected.

Rust 1.60.0 introduced `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. 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 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 in Rust 1.72 by turning the future incompatibility warning into an error. Users should still exercise 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.

Weakness: CWE-79 (Improper Neutralization of Input During Web Page Generation)

## Which versions are affected by CVE-2023-40030?

2 open source packages ship an affected version, including cargo. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `cargo` | crates.io | From 1.60.0 | 1.72 |
| `cargo` | crates.io | From 1.60.0 | 1.72 |
| `rust` | SUSE:Linux Enterprise Module for Development Tools 15 SP4 | All versions | 1.72.0-150400.24.24.1 |
| `rust1.72` | SUSE:Linux Enterprise Module for Development Tools 15 SP4 | All versions | 1.72.0-150400.9.3.1 |
| `rust` | SUSE:Linux Enterprise Module for Development Tools 15 SP5 | All versions | 1.72.0-150400.24.24.1 |
| `rust1.72` | SUSE:Linux Enterprise Module for Development Tools 15 SP5 | All versions | 1.72.0-150400.9.3.1 |
| `rust` | openSUSE:Leap 15.4 | All versions | 1.72.0-150400.24.24.1 |
| `rust1.72` | openSUSE:Leap 15.4 | All versions | 1.72.0-150400.9.3.1 |
| `rust` | openSUSE:Leap 15.5 | All versions | 1.72.0-150400.24.24.1 |
| `rust1.72` | openSUSE:Leap 15.5 | All versions | 1.72.0-150400.9.3.1 |
| `rust1.72` | openSUSE:Tumbleweed | All versions | 1.72.1-1.1 |

Products: Rust-Lang Rust.

## How do I fix CVE-2023-40030?

Upgrade cargo to 1.72 or later.

## Is CVE-2023-40030 being exploited?

There is no known exploitation of CVE-2023-40030 in the wild and no public exploit code.

## Other vulnerabilities in rust-lang cargo

- [CVE-2020-36318](https://insights.sbomify.com/CVE-2020-36318/): Use after free in n/a (critical 9.8)
- [CVE-2018-1000810](https://insights.sbomify.com/CVE-2018-1000810/): Integer overflow in n/a (critical 9.8)
- [CVE-2021-29922](https://insights.sbomify.com/CVE-2021-29922/): Security feature bypass in n/a (critical 9.1)
- [CVE-2024-43402](https://insights.sbomify.com/CVE-2024-43402/): Rust OS Command Injection/Argument Injection vulnerability (high 8.2)
- [CVE-2018-1000657](https://insights.sbomify.com/CVE-2018-1000657/): Memory corruption in n/a (high 7.8)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2023-40030 and fix it if it is affected.

What it is: CVE-2023-40030 is a medium-severity cross-site scripting vulnerability in rust-lang cargo, published on 24 Aug 2023. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.
Exploitation: There is no known exploitation of CVE-2023-40030 in the wild and no public exploit code.

Affected packages and fixed versions:
- cargo (crates.io): affected from 1.60.0; fixed in 1.72
- cargo (crates.io): affected from 1.60.0; fixed in 1.72

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2023-40030/ (Markdown: https://insights.sbomify.com/CVE-2023-40030/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2023-40030
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2023-40030
- OSV: https://osv.dev/vulnerability/CVE-2023-40030

---
From sbomify Insights: https://insights.sbomify.com/CVE-2023-40030/
Summaries are generated and may contain mistakes; the official description above is the record.
