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 package | Versions | Reported by |
|---|---|---|
| Unspecified product | n/a | CVE List |
| rust-embed (crates.io) | before 6.3.0, from 0.0.0-0 before 6.3.0 | GitHub Advisory Database, RustSec Advisory Database |
| rust-embed_project rust-embed | before 6.3.0 | NVD |
All scores
| GitHub | medium rating | |
| GitHub | 7.5high CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N |
| NVD | 7.5high CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N |
| NVD | 5.0medium CVSS:2.0 | AV: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
| https://rustsec.org/advisories/RUSTSEC-2021-0126.html | advisory, exploit, issue-tracking, third-party-advisory, web | |
| https://raw.githubusercontent.com/rustsec/advisory-db/main/crates/rust-embed/RUSTSEC-2021-0126.md | exploit, third-party-advisory, web | |
| https://github.com/pyros2097/rust-embed/issues/159 | report, web | |
| https://github.com/pyros2097/rust-embed | package | |
| https://nvd.nist.gov/vuln/detail/CVE-2021-45712 | advisory | |
| https://crates.io/crates/rust-embed | package | |
Sources
| Source | Record | Licence |
|---|---|---|
| CVE List | CVE-2021-45712 changed 2024-08-04 | CVE Terms of Use |
| GitHub Advisory Database | GHSA-cgw6-f3mj-h742 changed 2023-11-08 | CC-BY-4.0 |
| GitHub Advisory Database | GHSA-xrg3-hmf3-rvgw changed 2023-11-08 | CC-BY-4.0 |
| RustSec Advisory Database | RUSTSEC-2021-0126 changed 2023-11-08 | CC0-1.0 |
| NVD | CVE-2021-45712 changed 2026-06-17 | Public domain |