{"record":{"id":"ddcbdac4cddc3b62","repo":"jdx/mise","slug":"invalid-blob-digest-expected-sha256-prefix-di","errorCode":null,"errorMessage":"invalid blob digest (expected sha256: prefix): {digest}","messagePattern":"invalid blob digest \\(expected sha256: prefix\\): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/oci/layout.rs","lineNumber":140,"sourceCode":"        };\n        let path = self.root.join(\"index.json\");\n        file::write(&path, serde_json::to_vec_pretty(&index)?)?;\n        Ok(())\n    }\n\n    pub(crate) fn write_manifest(&self, manifest: &ImageManifest) -> Result<(String, u64)> {\n        let bytes = serde_json::to_vec(manifest)?;\n        self.write_blob(&bytes)\n    }\n}\n\n/// Validate that `digest` is a well-formed `sha256:<64 lowercase hex>` string.\n/// Guards against path traversal from a malicious registry returning something\n/// like `sha256:../../etc/passwd` as a layer digest — without this check, that\n/// would be used directly as a filesystem path component.\npub(crate) fn validate_sha256_digest(digest: &str) -> Result<()> {\n    let Some(hex) = digest.strip_prefix(\"sha256:\") else {\n        eyre::bail!(\"invalid blob digest (expected sha256: prefix): {digest}\");\n    };\n    if hex.len() != 64\n        || !hex\n            .chars()\n            .all(|c| c.is_ascii_digit() || ('a'..='f').contains(&c))\n    {\n        eyre::bail!(\"invalid blob digest (expected 64 lowercase hex chars): {digest}\");\n    }\n    Ok(())\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    #[test]\n    fn rejects_path_traversal() {\n        assert!(validate_sha256_digest(\"sha256:../../etc/passwd\").is_err());","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/oci/layout.rs#L122-L158","documentation":"Before using a digest as a filesystem path component in the blob store, mise validates that it is well-formed `sha256:<64 lowercase hex>`. A digest without the `sha256:` prefix is rejected with this error. This is a security guard against path traversal (e.g. `sha256:../../etc/passwd` from a malicious registry).","triggerScenarios":"Calling `write_blob_with_digest` or `read_blob` with a digest string that lacks the `sha256:` prefix — e.g. passing a bare hex hash, an `sha512:` digest, or an unvalidated string taken from a registry response or user config.","commonSituations":"Hand-building digests in scripts and forgetting the prefix; a registry manifest using a non-sha256 algorithm; passing a manifest/media-type digest instead of a blob digest.","solutions":["Prefix the value with `sha256:` before passing it to the blob API","Verify the digest source: use only digests taken from validated manifest fields or computed with SHA-256 yourself","Reconfigure the registry/image reference to one that publishes sha256 digests"],"exampleFix":"// before\nwrite_blob_with_digest(\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\", &bytes)\n// after\nwrite_blob_with_digest(\"sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\", &bytes)","handlingStrategy":"validation","validationCode":"fn has_sha256_prefix(d: &str) -> bool { d.starts_with(\"sha256:\") }\n// guard before calling read_blob/write_blob_with_digest","typeGuard":"fn is_sha256_digest(d: &str) -> bool {\n    d.strip_prefix(\"sha256:\")\n        .map(|h| h.len() == 64 && h.chars().all(|c| c.is_ascii_digit() || ('a'..='f').contains(&c)))\n        .unwrap_or(false)\n}","tryCatchPattern":"match layout.read_blob(digest) {\n    Err(e) if e.to_string().contains(\"expected sha256: prefix\") => {\n        eprintln!(\"{digest:?} is not a sha256 blob digest; check manifest source\");\n    }\n    Err(e) => return Err(e),\n    Ok(b) => b,\n}","preventionTips":["Never pass digests straight from external input without format validation","Treat digests as opaque strings from validated manifest fields only","Keep digests lowercase end-to-end","Unit-test digest handling with malformed inputs"],"tags":["oci","digest","validation"],"backgroundTag":"invalid-argument-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"}