jdx/mise · error

invalid blob digest (expected sha256: prefix)

Error message

invalid blob digest (expected sha256: prefix): {digest}

What it means

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).

Solutions

  1. Prefix the value with `sha256:` before passing it to the blob API
  2. Verify the digest source: use only digests taken from validated manifest fields or computed with SHA-256 yourself
  3. Reconfigure the registry/image reference to one that publishes sha256 digests

Example fix

// before
write_blob_with_digest("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", &bytes)
// after
write_blob_with_digest("sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", &bytes)
Defensive patterns

Strategy: validation

Validate before calling

fn has_sha256_prefix(d: &str) -> bool { d.starts_with("sha256:") }
// guard before calling read_blob/write_blob_with_digest

Type guard

fn is_sha256_digest(d: &str) -> bool {
    d.strip_prefix("sha256:")
        .map(|h| h.len() == 64 && h.chars().all(|c| c.is_ascii_digit() || ('a'..='f').contains(&c)))
        .unwrap_or(false)
}

Try / catch

match layout.read_blob(digest) {
    Err(e) if e.to_string().contains("expected sha256: prefix") => {
        eprintln!("{digest:?} is not a sha256 blob digest; check manifest source");
    }
    Err(e) => return Err(e),
    Ok(b) => b,
}

Prevention

When it happens

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

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

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17). Data as JSON: /api/errors/ddcbdac4cddc3b62. Report an issue: GitHub.

Appendix: source

Thrown at src/oci/layout.rs:140

        };
        let path = self.root.join("index.json");
        file::write(&path, serde_json::to_vec_pretty(&index)?)?;
        Ok(())
    }

    pub(crate) fn write_manifest(&self, manifest: &ImageManifest) -> Result<(String, u64)> {
        let bytes = serde_json::to_vec(manifest)?;
        self.write_blob(&bytes)
    }
}

/// Validate that `digest` is a well-formed `sha256:<64 lowercase hex>` string.
/// Guards against path traversal from a malicious registry returning something
/// like `sha256:../../etc/passwd` as a layer digest — without this check, that
/// would be used directly as a filesystem path component.
pub(crate) fn validate_sha256_digest(digest: &str) -> Result<()> {
    let Some(hex) = digest.strip_prefix("sha256:") else {
        eyre::bail!("invalid blob digest (expected sha256: prefix): {digest}");
    };
    if hex.len() != 64
        || !hex
            .chars()
            .all(|c| c.is_ascii_digit() || ('a'..='f').contains(&c))
    {
        eyre::bail!("invalid blob digest (expected 64 lowercase hex chars): {digest}");
    }
    Ok(())
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn rejects_path_traversal() {
        assert!(validate_sha256_digest("sha256:../../etc/passwd").is_err());

View on GitHub (pinned to 533346cc37)