{"record":{"id":"09fdf86fe7eedb20","repo":"jdx/mise","slug":"invalid-recovery-content-identifier","errorCode":null,"errorMessage":"invalid recovery content identifier","messagePattern":"invalid recovery content identifier","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/history/recovery.rs","lineNumber":123,"sourceCode":"    }\n    restore(state_dir, path, prior)\n}\n\nfn validate_destination(path: &Path) -> Result<()> {\n    if !path.is_absolute() || path.components().any(|c| matches!(c, Component::ParentDir)) {\n        bail!(\"invalid recovery destination\");\n    }\n    for parent in path.ancestors().skip(1) {\n        if std::fs::symlink_metadata(parent).is_ok_and(|meta| meta.is_symlink()) {\n            bail!(\"a parent directory is now a symlink; left untouched\");\n        }\n    }\n    Ok(())\n}\n\nfn validate_blob_id(hash: &str) -> Result<()> {\n    if hash.len() != 64 || !hash.bytes().all(|b| b.is_ascii_hexdigit()) {\n        bail!(\"invalid recovery content identifier\");\n    }\n    Ok(())\n}\n\npub(super) fn read_blob(state_dir: &Path, blob: &Blob) -> Result<Vec<u8>> {\n    use base64::Engine;\n    validate_blob_id(&blob.sha256)?;\n    let bytes = match &blob.inline {\n        Some(inline) => base64::engine::general_purpose::STANDARD.decode(inline)?,\n        None => {\n            let path = super::journal::blobs_dir_in(state_dir).join(&blob.sha256);\n            let metadata = std::fs::symlink_metadata(&path)?;\n            if !metadata.is_file() || metadata.len() != blob.size {\n                bail!(\"invalid recovery content file\");\n            }\n            std::fs::read(path)?\n        }\n    };","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/history/recovery.rs#L105-L141","documentation":"validate_blob_id enforces that every recovery blob identifier is exactly 64 lowercase/uppercase ASCII hex characters — a SHA-256 hex digest. Recovery blob filenames are joined directly into the blobs directory path, so an identifier with other characters could traverse directories or reference a corrupt record; anything failing the shape check is rejected before any filesystem access.","triggerScenarios":"Calling read_blob or discard_except with a Blob whose sha256 field is not 64 hex chars: empty string, truncated digest, base64 instead of hex, a `sha256:<hex>` prefixed string, or an id containing `/`, `..`, or whitespace.","commonSituations":"Hand-editing or partially copying journal/blob metadata; tooling that stored a digest with a `sha256:` prefix; truncated or corrupted journal entries from a crashed process.","solutions":["Fix the sha256 value in the snapshot/journal metadata so it is exactly 64 hex characters","Regenerate the snapshot if the journal metadata is corrupted rather than hand-editing ids","If the id came from upstream input, normalize it (strip prefix, lowercase, re-encode from raw bytes) before storing it in the Blob"],"exampleFix":"// before\nlet blob = Blob { sha256: \"sha256:abc123\".into(), .. };\n// after\nlet hex = \"sha256:abc123\".trim_start_matches(\"sha256:\");\nassert_eq!(hex.len(), 64);\nlet blob = Blob { sha256: hex.to_ascii_lowercase(), .. };","handlingStrategy":"validation","validationCode":"fn valid_blob_id(s: &str) -> bool {\n    s.len() == 64 && s.bytes().all(|b| b.is_ascii_hexdigit())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Store digests as plain 64-char lowercase hex, never prefixed or base64","Validate ids at deserialization/import time","Never hand-edit journal or blob metadata files"],"tags":["validation","sha256","corruption"],"backgroundTag":"invalid-identifier-format","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"}