jdx/mise · error

output path traverses symlink ancestor

Error message

output path {} traverses symlink ancestor {}

What it means

ensure_no_symlink_ancestors walks each intermediate directory of a cache output path and fails if any ancestor is a symlink. Cache restore replaces directories in place; following symlinked ancestors could write artifacts outside the task directory, so mise rejects it as a safety measure.

Solutions

  1. Replace the symlinked ancestor directory with a real directory inside the task dir
  2. Move the symlink target's contents into the task directory and update the output path
  3. Exclude symlinked subtrees from the outputs declaration

Example fix

# before: out -> /mnt/shared/out
rm out && mkdir out
# after: out is a real directory containing dist/
Defensive patterns

Strategy: validation

Validate before calling

# ensure no ancestor of the output is a symlink
for d in out out/dist; do [ -L "$d" ] && echo "$d is a symlink"; done

Try / catch

if err contains 'traverses symlink ancestor':
    replace_symlink_with_real_directory(err.path)

Prevention

When it happens

Trigger: A cache output like `out/dist/file` where `out` (or any intermediate dir) is a symlink to elsewhere; triggered when installing/restoring cached outputs under the task root.

Common situations: Users symlinking output dirs to another disk or shared cache; package managers creating node_modules symlinks inside output trees; pnpm-style symlink layouts under output paths.

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/442b365430b08eab. Report an issue: GitHub.

Appendix: source

Thrown at src/task/task_cache.rs:1336

    roots.sort_by_key(|path| path.components().count());
    let mut result = Vec::<PathBuf>::new();
    for root in roots {
        if !result.iter().any(|parent| root.starts_with(parent)) {
            result.push(root);
        }
    }
    result.sort();
    result
}

fn ensure_no_symlink_ancestors(root: &Path, rel: &Path) -> Result<()> {
    let mut current = root.to_path_buf();
    let component_count = rel.components().count();
    for component in rel.components().take(component_count.saturating_sub(1)) {
        current.push(component);
        match fs::symlink_metadata(&current) {
            Ok(metadata) if metadata.file_type().is_symlink() => {
                bail!(
                    "output path {} traverses symlink ancestor {}",
                    rel.display(),
                    current.display()
                );
            }
            Ok(_) => {}
            Err(err) if err.kind() == std::io::ErrorKind::NotFound => {}
            Err(err) => return Err(err.into()),
        }
    }
    Ok(())
}

fn install_transactionally(
    root: &Path,
    staging: &Path,
    install_roots: &[PathBuf],
    remove_roots: &[PathBuf],

View on GitHub (pinned to 533346cc37)