GHSA-cgw6-f3mj-h742: Rust embed Path Traversal Vulnerability

MODERATE
CWE-22
Published
Advisory Summary

GHSA-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

CVE Identifier N/A
GHSA Identifier GHSA-cgw6-f3mj-h742
Severity MODERATE
CVSS v3.1 Base Score N/A
CWE Classification CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Affected Product Rust embed
Package Ecosystem crates.io
Published Date
Last Updated

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.

rust-embed fixed: 6.3.0
Upgrade rust-embed to 6.3.0
Verify Direct and Transitive Dependencies

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

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. ```rust #[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.

GHSA-cgw6-f3mj-h742 Affected Rust embed Versions

1 component(s)
Fixed Versions:
6.3.0
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?
GHSA-cgw6-f3mj-h742 is a security vulnerability in Rust embed involving RustEmbed generated `get` method allows for directory traversal when reading files from disk under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Which Rust embed versions are affected?
Affected versions include releases prior to 6.3.0 across affected packages: rust-embed.
What version fixes GHSA-cgw6-f3mj-h742?
Upgrading to 6.3.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is rust-embed affected?
Yes, rust-embed is affected in releases prior to 6.3.0. Upgrade your dependency to 6.3.0 or later.
What CWE is associated with GHSA-cgw6-f3mj-h742?
GHSA-cgw6-f3mj-h742 is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') (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.).
How can I check crates.io dependencies for GHSA-cgw6-f3mj-h742?
Run the dependency tree command: 'inspect dependencies for rust-embed'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "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
  }
}