{"record":{"id":"eefd55471e59f78f","repo":"jdx/mise","slug":"native-cargo-binary-path-must-stay-inside-the-arti","errorCode":null,"errorMessage":"native cargo binary path must stay inside the artifact: {}","messagePattern":"native cargo binary path must stay inside the artifact: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/backend/cargo/native_binstall.rs","lineNumber":1002,"sourceCode":"        if extract_dir.join(&candidate).is_dir() {\n            return format!(\"{candidate}/{{ bin }}{{ binary-ext }}\");\n        }\n    }\n    \"{ bin }{ binary-ext }\".to_string()\n}\n\nfn validate_native_bin_relative_path(path: &str) -> Result<PathBuf> {\n    let path = PathBuf::from(path);\n    if path.components().next().is_none() {\n        bail!(\"native cargo binary path is empty\");\n    }\n    if path.components().any(|component| {\n        matches!(\n            component,\n            Component::ParentDir | Component::Prefix(_) | Component::RootDir\n        )\n    }) {\n        bail!(\n            \"native cargo binary path must stay inside the artifact: {}\",\n            path.display()\n        );\n    }\n    Ok(path)\n}\n\nfn validate_native_bin_sources(pending: &[(PathBuf, PathBuf)]) -> Result<()> {\n    let mut sources = BTreeSet::new();\n    for (src, _) in pending {\n        if !sources.insert(src) {\n            bail!(\n                \"native cargo binary artifact maps multiple bins to {}\",\n                file::display_path(src)\n            );\n        }\n    }\n    Ok(())","sourceCodeStart":984,"sourceCodeEnd":1020,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/backend/cargo/native_binstall.rs#L984-L1020","documentation":"validate_native_bin_relative_path rejects paths that would escape the extracted artifact: any ParentDir (..), Prefix (drive/UNC on Windows), or RootDir component makes the path absolute or traversing, so extracting/installing through it could write outside the artifact directory. This is a path-traversal guard.","triggerScenarios":"Native binstall install where a bin path (from binstall metadata, bin_dir, or templated bin name) resolves to something like /abs/path, C:\\tool, ..\\..\\evil, or otherwise contains traversal components.","commonSituations":"Malicious or misconfigured crate binstall overrides containing absolute paths or `..` segments; hand-written tool options with a leading slash; template variables injecting unexpected prefixes.","solutions":["Fix the bin path/bin_dir in the tool options or crate binstall metadata to a plain relative path (e.g. `bin/tool`).","Avoid trusting third-party binstall overrides; pin versions with known-good metadata.","If the crate is untrusted, prefer a different backend/source or drop it entirely."],"exampleFix":"# before (mise.toml)\ncargo:mytool = { version = \"1.0\", bin = \"/opt/mytool/bin/mytool\" }\n\n# after\ncargo:mytool = { version = \"1.0\", bin = \"mytool\" }","handlingStrategy":"validation","validationCode":"// rust\nfn is_safe_relative(p: &Path) -> bool {\n    !p.is_absolute()\n        && p.components().all(|c| !matches!(c, Component::ParentDir | Component::Prefix(_) | Component::RootDir))\n}","typeGuard":"fn safe_bin_path(p: &str) -> Option<PathBuf> {\n    let p = PathBuf::from(p);\n    (!p.is_absolute()\n        && p.components().all(|c| !matches!(c, Component::ParentDir | Component::Prefix(_) | Component::RootDir)))\n    .then_some(p)\n}","tryCatchPattern":null,"preventionTips":["Always specify plain relative bin paths (no leading /, no .., no drive prefixes)","Distrust third-party binstall overrides; review them before use","Keep this traversal guard in any code that extracts archives to a fixed root"],"tags":["cargo","binstall","path-traversal","security"],"backgroundTag":"path-traversal-blocked","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}