Repository navigation
Verify model artifact SHA-256 at download and load time (closes #1715) - #1730
Merged
Merged
Conversation
Build-time (scripts/download-models.ts): pin the HuggingFace commit + SHA-256, verify the artifact after download (and any pre-existing file), delete + fail hard on mismatch so an unverified model is never bundled. curl -fL --proto =https; the pinned digest is the authoritative gate. Load-time (packages/nlp-engine): compute the on-disk GGUF's SHA-256 and refuse to load on mismatch before LlamaModel::load_from_file, closing the post-install tamper window. Adds EMBEDDING_MODEL_SHA256, compute_file_sha256, verify_model_integrity, EmbeddingError::IntegrityError, sha2 dep, and tests. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Contributor
Author
|
APPROVE Independent adversarial review (all 7 scrutiny points) returned CONFIRMED-GOOD: the load-time gate runs before |
This was referenced Jul 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes the last unmet leg of the T9 supply-chain bar (ADR-058): the build-time model download did
curl -Lwith no SHA-256 verification, so a substitutednomic-embed-text-v1.5.Q8_0.gguf(compromised upstream, redirect hijack, MITM on a CI runner, malicious mirror) would be code-signed and notarized as authentic, then parsed by native llama.cpp inside the daemon with full authority. This adds digest verification at both the download and the load site.The runtime chat-model download (
model_manager.rs) was already hardened (#1543); this is the separate build/bundle path it never touched, plus the companion load-time check.Changes
Build-time —
scripts/download-models.tsresolve/0188c9bf…/) somaincan't move under us, and pinMODEL_SHA256.curl -fL --proto =https(fail-hard on HTTP errors, HTTPS-only). The digest is the authoritative gate regardless of redirect target.sha256File()(Bun.CryptoHasher) verifies the artifact after download; on mismatch it deletes the file and throws — never bundles an unverified model.Load-time —
packages/nlp-engine/config.rs: pinnedEMBEDDING_MODEL_SHA256(single source of truth, kept in lockstep with the script), a streamingcompute_file_sha256()(64 KB chunks — a 146 MB GGUF never buffers whole), andverify_model_integrity().embedding.rs: right after the model path resolves and beforeLlamaModel::load_from_file, verify the on-disk bytes; refuse to load on mismatch. This closes the post-install tamper window — a model swapped on disk after install is rejected.error.rs: newEmbeddingError::IntegrityErrorso the failure is legible (not folded into a generic load error).Cargo.toml:sha2 = "0.10".Digest rotation is a single-change contract: rotating the model updates the commit + digest in the script AND the
EMBEDDING_MODEL_SHA256const together (called out in both comments).Acceptance criteria
MODEL_URL+ a matching constant at the Rust load siteVerification
3e24342164b3d94991ba9692fdc0dd08e3fd7362e0aacc396a9a5c54a544c3b7); the shipped local model matches it.sha256("abc")vector, mismatch rejection, unreadable-file error, digest-format invariant.cargo clippy -p nodespace-nlp-engineclean;cargo test --libgreen. No fake-model test exists, and integration tests skip when the model is absent / use the real default config, so the load gate introduces no test breakage.Closes #1715.