{"record":{"id":"7245533563c3d2d7","repo":"jdx/mise","slug":"invalid-path-inside-recovery-directory","errorCode":null,"errorMessage":"invalid path inside recovery directory","messagePattern":"invalid path inside recovery directory","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/history/recovery.rs","lineNumber":169,"sourceCode":"            read_blob(state_dir, content)?;\n        }\n        PathSnapshot::Dir {\n            files, links, dirs, ..\n        } => {\n            let mut seen = BTreeSet::new();\n            for relative in files\n                .iter()\n                .map(|f| &f.rel)\n                .chain(links.iter().map(|f| &f.rel))\n                .chain(dirs.iter().map(|f| &f.rel))\n            {\n                if relative.as_os_str().is_empty()\n                    || !relative\n                        .components()\n                        .all(|c| matches!(c, Component::Normal(_)))\n                    || !seen.insert(relative)\n                {\n                    bail!(\"invalid path inside recovery directory\");\n                }\n            }\n            for leaf in files\n                .iter()\n                .map(|f| &f.rel)\n                .chain(links.iter().map(|f| &f.rel))\n            {\n                if seen\n                    .iter()\n                    .any(|other| *other != leaf && other.starts_with(leaf))\n                {\n                    bail!(\"recovery directory descends through a file or symlink\");\n                }\n            }\n            for file in files {\n                read_blob(state_dir, &file.content)?;\n            }\n        }","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/history/recovery.rs#L151-L187","documentation":"validate_snapshot checks each relative path recorded in the snapshot (dirs, files, links). A relative path is rejected if it is empty, contains any component that is not a plain Normal component (so `..`, `.`, or absolute/root components are disallowed), or duplicates one already seen. This guarantees recovery only ever touches paths strictly inside the recovery directory.","triggerScenarios":"recover_path on a snapshot whose journal contains an empty rel path, a rel with `..` or `.` components, or the same relative path appearing twice across dirs/files/links entries — typically from hand-edited, imported, or corrupted journal metadata.","commonSituations":"Journals merged or imported from external sources with path normalization differences; corrupted metadata after a crash; duplicated entries from a bug in the recording tooling; scripts writing raw rel paths without normalization.","solutions":["Fix or remove the offending rel entry in the snapshot journal so every path is a non-empty sequence of Normal components and unique","Re-record the snapshot so the journal is regenerated with normalized relative paths","Deduplicate entries if the same path was recorded twice","Reject the input at import time by validating each rel path before accepting it"],"exampleFix":"// before\nfiles.push(FileEntry { rel: PathBuf::from(\"a/../../etc/passwd\"), .. });\n// after\nlet rel = path.strip_prefix(&root)?; // ensure it is inside the recovery dir\nassert!(rel.components().all(|c| matches!(c, Component::Normal(_))));\nfiles.push(FileEntry { rel: rel.to_path_buf(), .. });","handlingStrategy":"validation","validationCode":"use std::path::Component;\nfn rel_ok(rel: &std::path::Path) -> bool {\n    !rel.as_os_str().is_empty()\n        && rel.components().all(|c| matches!(c, Component::Normal(_)))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive rel paths with strip_prefix from the snapshot root, never string slicing","Deduplicate entries before serializing the snapshot","Validate all rel paths when importing or merging journals"],"tags":["validation","path","journal"],"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"}