Skip to main content

Module binhash

Module binhash 

Source
Expand description

Binary-hash pinning for stdio addons (P3 — supply-chain hardening).

A stdio addon spawns a local executable. Pinning that binary’s SHA-256 in the manifest ([mcp] sha256 = "…") closes the gap between what was audited and what actually runs: if the file on PATH is swapped after install, the hash no longer matches and the gateway refuses to spawn it.

SHA-256 (not the engine’s internal BLAKE3) is deliberate — an author pins the value an ordinary sha256sum my-mcp / shasum -a 256 my-mcp prints, so the pin is reproducible without lean-ctx.

Functions§

resolve_on_path
Resolve a stdio command to a concrete file path. An absolute/relative path (anything containing a separator) is used as-is; a bare name is looked up on PATH, honouring PATHEXT-free Unix semantics (first executable match).
sha256_file
Stream-hash a file and return its lowercase hex SHA-256. Streaming (8 KiB chunks) keeps memory flat regardless of binary size.
verify_binary
Verify that command resolves to a binary whose SHA-256 equals expected_sha256. An empty expected_sha256 means “no pin” → Ok. The comparison is case-insensitive over hex; any mismatch, unresolved binary, or read error is a hard failure (fail-closed — a pin you cannot check is a pin that failed).