jdx/mise · error

path must be a non-empty relative path

Error message

path must be a non-empty relative path

What it means

ensure_safe_relative validates that a path used inside the cache (manifest roots, output roots) is a non-empty relative path with no dangerous components (parent traversal, absolute root, Windows prefix). It is a path-traversal guard: cache data must only ever address content inside the cache/staging directories.

Solutions

  1. Fix the configured output pattern/root to be a relative path like "dist" (no leading /, no ..).
  2. Delete cache entries whose manifests contain absolute or traversing paths and regenerate them.
  3. Never trust manifests from untrusted remote caches; treat them as data, not config.
  4. Use `mise tasks info <task>` to confirm resolved outputs are relative.

Example fix

// before (mise.toml)
outputs = ["/absolute/dist"]
// after
outputs = ["dist"]
Defensive patterns

Strategy: validation

Validate before calling

import { isAbsolute, resolve } from 'path';
function isSafeRelative(p: string): boolean {
  return p.length > 0 && !isAbsolute(p) && !p.split('/').includes('..');
}

Type guard

function isSafeRelative(p: string): p is string {
  return p.length > 0 && !p.startsWith('/') && !p.includes('..') && !/^[A-Za-z]:/.test(p);
}

Try / catch

// reject unsafe paths before they reach cache code
if (!isSafeRelative(root)) throw new Error(`refusing unsafe cache path: ${root}`);

Prevention

When it happens

Trigger: Any call to ensure_safe_relative — e.g. validating manifest roots during restore — when the path is empty, absolute (starts with / or a Windows drive prefix), or contains `..` components. Also raised while validating output root resolution errors with wrap_err 'task X has an invalid cache output pattern'.

Common situations: Hand-edited or malicious cache manifests containing absolute or `../` paths; output patterns configured with absolute paths; corrupted manifest JSON from a bad remote cache.

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

Appendix: source

Thrown at src/task/task_cache.rs:1253

        } else {
            PathBuf::from(&output)
        };
        ensure_safe_relative(&path).wrap_err_with(|| {
            format!(
                "task {} cache output must stay within {}: {output}",
                task.name,
                root.display()
            )
        })?;
    }
    build_output_matcher(root, &patterns)
        .wrap_err_with(|| format!("task {} has an invalid cache output pattern", task.name))?;
    Ok(())
}

fn ensure_safe_relative(path: &Path) -> Result<()> {
    if path.as_os_str().is_empty() || path.is_absolute() {
        bail!("path must be a non-empty relative path");
    }
    if path.components().any(|c| {
        matches!(
            c,
            Component::ParentDir | Component::RootDir | Component::Prefix(_)
        )
    }) {
        bail!("path must not escape the task directory");
    }
    if !path.components().any(|c| matches!(c, Component::Normal(_))) {
        bail!("path must identify an output beneath the task directory");
    }
    Ok(())
}

fn resolve_output_roots(task: &Task, root: &Path, require_matches: bool) -> Result<Vec<PathBuf>> {
    let mut resolved = BTreeSet::new();
    let patterns = task.outputs.patterns();

View on GitHub (pinned to 533346cc37)