GHSA-cgw6-f3mj-h742: Rust embed Path Traversal Vulnerability
MODERATEGHSA-cgw6-f3mj-h742 is a MODERATE path traversal vulnerability (CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')) affecting Rust embed libraries in the crates.io ecosystem. The issue involves rustembed generated `get` method allows for directory traversal when reading files from disk. Remediation is available by upgrading affected packages to version 6.3.0.
GHSA-cgw6-f3mj-h742 at a Glance
How to Fix GHSA-cgw6-f3mj-h742
To remediate this vulnerability, upgrade all affected Rust embed dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
Upgrade rust-embed to 6.3.0
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
inspect dependencies for rust-embed
How to Check if You Are Affected
To determine whether your application is affected by GHSA-cgw6-f3mj-h742, inspect your project dependencies for Rust embed:
inspect dependencies for rust-embed
Analyze the terminal output to locate any version of Rust embed in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 6.3.0), your application is affected.
Note: Verify declared build manifests and deployed runtime container environments.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where the product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory. In Rust embed, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
GHSA-cgw6-f3mj-h742 Affected Rust embed Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
rust-embed
|
crates.io |
< 6.3.0
|
6.3.0
|
References
Frequently Asked Questions
What is GHSA-cgw6-f3mj-h742?
Which Rust embed versions are affected?
What version fixes GHSA-cgw6-f3mj-h742?
Is rust-embed affected?
What CWE is associated with GHSA-cgw6-f3mj-h742?
How can I check crates.io dependencies for GHSA-cgw6-f3mj-h742?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-cgw6-f3mj-h742",
"modified" : "2022-06-17T00:18:08Z",
"published" : "2022-06-17T00:18:08Z",
"aliases" : [ ],
"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",
"severity" : [ ],
"affected" : [ {
"package" : {
"ecosystem" : "crates.io",
"name" : "rust-embed"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "6.3.0"
} ]
} ]
} ],
"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"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-22" ],
"severity" : "MODERATE",
"github_reviewed" : true,
"github_reviewed_at" : "2022-06-17T00:18:08Z",
"nvd_published_at" : null
}
}