jdx/mise · error

invalid path inside recovery directory

Error message

invalid path inside recovery directory

What it means

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.

Solutions

  1. Fix or remove the offending rel entry in the snapshot journal so every path is a non-empty sequence of Normal components and unique
  2. Re-record the snapshot so the journal is regenerated with normalized relative paths
  3. Deduplicate entries if the same path was recorded twice
  4. Reject the input at import time by validating each rel path before accepting it

Example fix

// before
files.push(FileEntry { rel: PathBuf::from("a/../../etc/passwd"), .. });
// after
let rel = path.strip_prefix(&root)?; // ensure it is inside the recovery dir
assert!(rel.components().all(|c| matches!(c, Component::Normal(_))));
files.push(FileEntry { rel: rel.to_path_buf(), .. });
Defensive patterns

Strategy: validation

Validate before calling

use std::path::Component;
fn rel_ok(rel: &std::path::Path) -> bool {
    !rel.as_os_str().is_empty()
        && rel.components().all(|c| matches!(c, Component::Normal(_)))
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

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

Appendix: source

Thrown at src/system/history/recovery.rs:169

            read_blob(state_dir, content)?;
        }
        PathSnapshot::Dir {
            files, links, dirs, ..
        } => {
            let mut seen = BTreeSet::new();
            for relative in files
                .iter()
                .map(|f| &f.rel)
                .chain(links.iter().map(|f| &f.rel))
                .chain(dirs.iter().map(|f| &f.rel))
            {
                if relative.as_os_str().is_empty()
                    || !relative
                        .components()
                        .all(|c| matches!(c, Component::Normal(_)))
                    || !seen.insert(relative)
                {
                    bail!("invalid path inside recovery directory");
                }
            }
            for leaf in files
                .iter()
                .map(|f| &f.rel)
                .chain(links.iter().map(|f| &f.rel))
            {
                if seen
                    .iter()
                    .any(|other| *other != leaf && other.starts_with(leaf))
                {
                    bail!("recovery directory descends through a file or symlink");
                }
            }
            for file in files {
                read_blob(state_dir, &file.content)?;
            }
        }

View on GitHub (pinned to 533346cc37)