{"id":"CVE-2021-45712","aliases":["CVE-2021-45712","GHSA-cgw6-f3mj-h742","GHSA-xrg3-hmf3-rvgw","RUSTSEC-2021-0126"],"related":[],"kind":"vulnerability","state":"published","title":"RustEmbed generated `get` method allows for directory traversal when reading files from disk","summary":"An issue was discovered in the rust-embed crate before 6.3.0 for Rust. A ../ directory traversal can sometimes occur in debug mode.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"An issue was discovered in the rust-embed crate before 6.3.0 for Rust. A ../ directory traversal can sometimes occur in debug mode.","source":"cvelist"},{"lang":"en","text":"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.","format":"markdown","source":"ghsa"},{"lang":"en","text":"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.\n\nThis 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.","format":"markdown","source":"ghsa"},{"lang":"es","text":"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","source":"nvd"}],"published":"2021-11-29T12:00:00.000Z","modified":"2026-06-17T04:13:59.977Z","severity":{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N","score":7.5,"rating":"HIGH"},"severities":[{"scorer":"GitHub","scheme":"rating","rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N","score":7.5,"rating":"HIGH"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N","score":7.5,"rating":"HIGH"},{"scorer":"NVD","scheme":"CVSS:2.0","vector":"AV:N/AC:L/Au:N/C:P/I:N/A:N","score":5,"rating":"MEDIUM"}],"cwes":["CWE-22"],"affected":[{"ranges":[{"version":"n/a","status":"affected"}],"source":"cvelist"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"6.3.0"}],"ecosystem":"crates.io","package":"rust-embed","purl":"pkg:cargo/rust-embed","source":"ghsa"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"6.3.0"}],"ecosystem":"crates.io","package":"rust-embed","purl":"pkg:cargo/rust-embed","source":"ghsa"},{"ranges":[{"type":"semver","introduced":"0.0.0-0","status":"affected","fixed":"6.3.0"}],"ecosystem":"crates.io","package":"rust-embed","purl":"pkg:cargo/rust-embed","source":"rustsec"},{"ranges":[{"status":"affected","fixed":"6.3.0"}],"vendor":"rust-embed_project","product":"rust-embed","cpe":"cpe:2.3:a:rust-embed_project:rust-embed:*:*:*:*:*:rust:*:*","source":"nvd"}],"references":[{"url":"https://rustsec.org/advisories/RUSTSEC-2021-0126.html","tags":["advisory","exploit","issue-tracking","third-party-advisory","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","rustsec","nvd"]},{"url":"https://raw.githubusercontent.com/rustsec/advisory-db/main/crates/rust-embed/RUSTSEC-2021-0126.md","tags":["exploit","third-party-advisory","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/pyros2097/rust-embed/issues/159","tags":["report","web"],"sources":["ghsa","rustsec"]},{"url":"https://github.com/pyros2097/rust-embed","tags":["package"],"sources":["ghsa"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2021-45712","tags":["advisory"],"sources":["ghsa"]},{"url":"https://crates.io/crates/rust-embed","tags":["package"],"sources":["rustsec"]}],"credits":[],"assigner":"mitre","sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2021-45712","url":"https://www.cve.org/CVERecord?id=CVE-2021-45712","licence":"CVE Terms of Use","modified":"2024-08-04T04:47:02.168Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-cgw6-f3mj-h742","url":"https://github.com/advisories/GHSA-cgw6-f3mj-h742","licence":"CC-BY-4.0","modified":"2023-11-08T04:07:23.363Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-xrg3-hmf3-rvgw","url":"https://github.com/advisories/GHSA-xrg3-hmf3-rvgw","licence":"CC-BY-4.0","modified":"2023-11-08T04:07:23.363Z"},{"source":"rustsec","name":"RustSec Advisory Database","id":"RUSTSEC-2021-0126","url":"https://rustsec.org/advisories/RUSTSEC-2021-0126.html","licence":"CC0-1.0","modified":"2023-11-08T04:07:23.363Z"},{"source":"nvd","name":"NVD","id":"CVE-2021-45712","url":"https://nvd.nist.gov/vuln/detail/CVE-2021-45712","licence":"Public domain","modified":"2026-06-17T04:13:59.977Z"}],"updatedAt":"2026-11-25T22:58:06.251Z","epss":{"score":0.01645,"percentile":0.77164,"date":"2026-12-01T12:00:22.000Z"}}