{"record":{"id":"7a6d41a451c2b895","repo":"jdx/mise","slug":"path-must-be-a-non-empty-relative-path","errorCode":null,"errorMessage":"path must be a non-empty relative path","messagePattern":"path must be a non-empty relative path","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/task/task_cache.rs","lineNumber":1253,"sourceCode":"        } else {\n            PathBuf::from(&output)\n        };\n        ensure_safe_relative(&path).wrap_err_with(|| {\n            format!(\n                \"task {} cache output must stay within {}: {output}\",\n                task.name,\n                root.display()\n            )\n        })?;\n    }\n    build_output_matcher(root, &patterns)\n        .wrap_err_with(|| format!(\"task {} has an invalid cache output pattern\", task.name))?;\n    Ok(())\n}\n\nfn ensure_safe_relative(path: &Path) -> Result<()> {\n    if path.as_os_str().is_empty() || path.is_absolute() {\n        bail!(\"path must be a non-empty relative path\");\n    }\n    if path.components().any(|c| {\n        matches!(\n            c,\n            Component::ParentDir | Component::RootDir | Component::Prefix(_)\n        )\n    }) {\n        bail!(\"path must not escape the task directory\");\n    }\n    if !path.components().any(|c| matches!(c, Component::Normal(_))) {\n        bail!(\"path must identify an output beneath the task directory\");\n    }\n    Ok(())\n}\n\nfn resolve_output_roots(task: &Task, root: &Path, require_matches: bool) -> Result<Vec<PathBuf>> {\n    let mut resolved = BTreeSet::new();\n    let patterns = task.outputs.patterns();","sourceCodeStart":1235,"sourceCodeEnd":1271,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/task/task_cache.rs#L1235-L1271","documentation":"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.","triggerScenarios":"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'.","commonSituations":"Hand-edited or malicious cache manifests containing absolute or `../` paths; output patterns configured with absolute paths; corrupted manifest JSON from a bad remote cache.","solutions":["Fix the configured output pattern/root to be a relative path like \"dist\" (no leading /, no ..).","Delete cache entries whose manifests contain absolute or traversing paths and regenerate them.","Never trust manifests from untrusted remote caches; treat them as data, not config.","Use `mise tasks info <task>` to confirm resolved outputs are relative."],"exampleFix":"// before (mise.toml)\noutputs = [\"/absolute/dist\"]\n// after\noutputs = [\"dist\"]","handlingStrategy":"validation","validationCode":"import { isAbsolute, resolve } from 'path';\nfunction isSafeRelative(p: string): boolean {\n  return p.length > 0 && !isAbsolute(p) && !p.split('/').includes('..');\n}","typeGuard":"function isSafeRelative(p: string): p is string {\n  return p.length > 0 && !p.startsWith('/') && !p.includes('..') && !/^[A-Za-z]:/.test(p);\n}","tryCatchPattern":"// reject unsafe paths before they reach cache code\nif (!isSafeRelative(root)) throw new Error(`refusing unsafe cache path: ${root}`);","preventionTips":["Only ever configure relative output paths in mise.toml","Never trust manifests from untrusted remote caches","Purge entries whose manifests contain absolute or '..' paths"],"tags":["task-cache","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"}