jdx/mise · error

native cargo binary path must stay inside the artifact

Error message

native cargo binary path must stay inside the artifact: {}

What it means

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.

Solutions

  1. Fix the bin path/bin_dir in the tool options or crate binstall metadata to a plain relative path (e.g. `bin/tool`).
  2. Avoid trusting third-party binstall overrides; pin versions with known-good metadata.
  3. If the crate is untrusted, prefer a different backend/source or drop it entirely.

Example fix

# before (mise.toml)
cargo:mytool = { version = "1.0", bin = "/opt/mytool/bin/mytool" }

# after
cargo:mytool = { version = "1.0", bin = "mytool" }
Defensive patterns

Strategy: validation

Validate before calling

// rust
fn is_safe_relative(p: &Path) -> bool {
    !p.is_absolute()
        && p.components().all(|c| !matches!(c, Component::ParentDir | Component::Prefix(_) | Component::RootDir))
}

Type guard

fn safe_bin_path(p: &str) -> Option<PathBuf> {
    let p = PathBuf::from(p);
    (!p.is_absolute()
        && p.components().all(|c| !matches!(c, Component::ParentDir | Component::Prefix(_) | Component::RootDir)))
    .then_some(p)
}

Prevention

When it happens

Trigger: 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.

Common situations: Malicious or misconfigured crate binstall overrides containing absolute paths or `..` segments; hand-written tool options with a leading slash; template variables injecting unexpected prefixes.

Understand the failure class

Background: Path traversal blocked: "path escapes the workspace" and "outside site root" errors when a path will not stay inside its allowed directory — this error's family across 26 libraries.

Related errors


AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17). Data as JSON: /api/errors/eefd55471e59f78f. Report an issue: GitHub.

Appendix: source

Thrown at src/backend/cargo/native_binstall.rs:1002

        if extract_dir.join(&candidate).is_dir() {
            return format!("{candidate}/{{ bin }}{{ binary-ext }}");
        }
    }
    "{ bin }{ binary-ext }".to_string()
}

fn validate_native_bin_relative_path(path: &str) -> Result<PathBuf> {
    let path = PathBuf::from(path);
    if path.components().next().is_none() {
        bail!("native cargo binary path is empty");
    }
    if path.components().any(|component| {
        matches!(
            component,
            Component::ParentDir | Component::Prefix(_) | Component::RootDir
        )
    }) {
        bail!(
            "native cargo binary path must stay inside the artifact: {}",
            path.display()
        );
    }
    Ok(path)
}

fn validate_native_bin_sources(pending: &[(PathBuf, PathBuf)]) -> Result<()> {
    let mut sources = BTreeSet::new();
    for (src, _) in pending {
        if !sources.insert(src) {
            bail!(
                "native cargo binary artifact maps multiple bins to {}",
                file::display_path(src)
            );
        }
    }
    Ok(())

View on GitHub (pinned to 533346cc37)