{"id":"CVE-2021-45712","aliases":["GHSA-xrg3-hmf3-rvgw","RUSTSEC-2021-0126"],"url":"https://o3.security/vulnerability/CVE-2021-45712","summary":"RustEmbed generated `get` method allows for directory traversal when reading files from disk","details":"When running in debug mode and the `debug-embed` (off by default) feature is\nnot enabled, the generated `get` method does not check that the input path is\na child of the folder given. \n\nThis allows attackers to read arbitrary files in the file system if they have\ncontrol over the filename given. The following code will print the contents of\nyour `/etc/passwd` if adjusted with a correct number of `../`s depending on\nwhere it is run from.\n\n```rust\n#[derive(rust_embed::RustEmbed)]\n#[folder = \"src/\"]\npub struct Asset;\n\nfn main() {\n    let d = Asset::get(\"../../../etc/passwd\").unwrap().data;\n    println!(\"{}\", String::from_utf8_lossy(&d));\n}\n```\n\nThe flaw was corrected by canonicalizing the input filename and ensuring that\nit starts with the canonicalized folder path.\n","published":"2022-06-17T00:18:08Z","modified":"2023-11-08T04:07:23.363783Z","cvss":null,"epss":{"score":0.01593,"percentile":0.73787,"asOf":"2026-08-21"},"cisaKev":null,"exploitsKnown":2,"affectedPackages":[{"ecosystem":"crates.io","name":"rust-embed","fixedVersion":"6.3.0"}],"fix":null,"references":[{"type":"WEB","url":"https://github.com/pyros2097/rust-embed/issues/159"},{"type":"PACKAGE","url":"https://github.com/pyros2097/rust-embed"},{"type":"WEB","url":"https://rustsec.org/advisories/RUSTSEC-2021-0126.html"}],"provenance":{"sources":["OSV.dev","FIRST.org (EPSS)"],"lastVerified":"2023-11-08T04:07:23.363783Z"}}