CVE-2021-45712
JSON

7.5high

RustEmbed generated `get` method allows for directory traversal when reading files from disk

Severity
7.5high CVSS:3.1 by NVD
Exploit likelihood
1.65% (higher than 77% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
mitre
Also known as
GHSA-cgw6-f3mj-h742GHSA-xrg3-hmf3-rvgwRUSTSEC-2021-0126

Description

An issue was discovered in the rust-embed crate before 6.3.0 for Rust. A ../ directory traversal can sometimes occur in debug mode.

Affected

Product or packageVersionsReported by
Unspecified productn/aCVE List
rust-embed (crates.io)before 6.3.0, from 0.0.0-0 before 6.3.0GitHub Advisory Database, RustSec Advisory Database
rust-embed_project rust-embedbefore 6.3.0NVD

All scores

GitHubmedium rating
GitHub7.5high CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NVD7.5high CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NVD5.0medium CVSS:2.0AV:N/AC:L/Au:N/C:P/I:N/A:N

Classification

What each source says

CVE List

An issue was discovered in the rust-embed crate before 6.3.0 for Rust. A ../ directory traversal can sometimes occur in debug mode.

GitHub Advisory Database

When running in debug mode and the debug-embed (off by default) feature is not enabled, the generated get method does not check that the input path is a child of the folder given.

This allows attackers to read arbitrary files in the file system if they have control over the filename given. The following code will print the contents of your /etc/passwd if adjusted with a correct number of ../s depending on where it is run from.

#[derive(rust_embed::RustEmbed)]
#[folder = "src/"]
pub struct Asset;

fn main() {
    let d = Asset::get("../../../etc/passwd").unwrap().data;
    println!("{}", String::from_utf8_lossy(&d));
}

The flaw was corrected by canonicalizing the input filename and ensuring that it starts with the canonicalized folder path.

GitHub Advisory Database

When running in debug mode and the debug-embed (off by default) feature is not enabled, the generated get method does not check that the input path is a child of the folder given.

This allows attackers to read arbitrary files in the file system if they have control over the filename given. The following code will print the contents of your /etc/passwd if adjusted with a correct number of ../s depending on where it is run from.

NVD (es)

Se ha detectado un problema en la crate rust-embed versiones anteriores a 6.3.0 para Rust. A veces puede producirse un salto de directorio ../ en modo de depuración

References

Sources

SourceRecordLicence
CVE ListCVE-2021-45712 changed 2024-08-04CVE Terms of Use
GitHub Advisory DatabaseGHSA-cgw6-f3mj-h742 changed 2023-11-08CC-BY-4.0
GitHub Advisory DatabaseGHSA-xrg3-hmf3-rvgw changed 2023-11-08CC-BY-4.0
RustSec Advisory DatabaseRUSTSEC-2021-0126 changed 2023-11-08CC0-1.0
NVDCVE-2021-45712 changed 2026-06-17Public domain