{"record":{"id":"442b365430b08eab","repo":"jdx/mise","slug":"output-path-traverses-symlink-ancestor","errorCode":null,"errorMessage":"output path {} traverses symlink ancestor {}","messagePattern":"output path (.+?) traverses symlink ancestor (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/task/task_cache.rs","lineNumber":1336,"sourceCode":"    roots.sort_by_key(|path| path.components().count());\n    let mut result = Vec::<PathBuf>::new();\n    for root in roots {\n        if !result.iter().any(|parent| root.starts_with(parent)) {\n            result.push(root);\n        }\n    }\n    result.sort();\n    result\n}\n\nfn ensure_no_symlink_ancestors(root: &Path, rel: &Path) -> Result<()> {\n    let mut current = root.to_path_buf();\n    let component_count = rel.components().count();\n    for component in rel.components().take(component_count.saturating_sub(1)) {\n        current.push(component);\n        match fs::symlink_metadata(&current) {\n            Ok(metadata) if metadata.file_type().is_symlink() => {\n                bail!(\n                    \"output path {} traverses symlink ancestor {}\",\n                    rel.display(),\n                    current.display()\n                );\n            }\n            Ok(_) => {}\n            Err(err) if err.kind() == std::io::ErrorKind::NotFound => {}\n            Err(err) => return Err(err.into()),\n        }\n    }\n    Ok(())\n}\n\nfn install_transactionally(\n    root: &Path,\n    staging: &Path,\n    install_roots: &[PathBuf],\n    remove_roots: &[PathBuf],","sourceCodeStart":1318,"sourceCodeEnd":1354,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/task/task_cache.rs#L1318-L1354","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Replace the symlinked ancestor directory with a real directory inside the task dir","Move the symlink target's contents into the task directory and update the output path","Exclude symlinked subtrees from the outputs declaration"],"exampleFix":"# before: out -> /mnt/shared/out\nrm out && mkdir out\n# after: out is a real directory containing dist/","handlingStrategy":"validation","validationCode":"# ensure no ancestor of the output is a symlink\nfor d in out out/dist; do [ -L \"$d\" ] && echo \"$d is a symlink\"; done","typeGuard":null,"tryCatchPattern":"if err contains 'traverses symlink ancestor':\n    replace_symlink_with_real_directory(err.path)","preventionTips":["Don't symlink output directories elsewhere (network mounts, shared caches)","Prefer bind mounts or copying over symlinks inside task dirs","Audit generated trees (node_modules etc.) for symlinked parents"],"tags":["symlink","security","task-cache"],"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"}