Repository navigation
Add load-time SHA-256 integrity gate for the chat model (#1729) - #1749
Merged
Merged
Conversation
The embedding model verifies its GGUF against a pinned digest before native llama.cpp loads it; the chat/LLM model had no equivalent. A model correctly downloaded but swapped/tampered on disk was loaded without re-verification — the same post-install tamper window, into C++ with full authority. chat/mod.rs load_model now takes an optional expected SHA-256 and, when present, verifies the on-disk file (via the extracted generic verify_file_sha256) before load_from_file, refusing on mismatch with ChatError::IntegrityError. The agent resolves the digest from the model file's basename against the catalog (expected_sha256_for_filename), preserving the agent -> nlp-engine dependency direction. A non-catalog / user-supplied path resolves to None and loads with a warning (nothing to verify against). Digest comparison is case-insensitive. Closes #1729. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Contributor
Author
|
APPROVE Independent adversarial review — no bypass, correctness bug, or regression:
Folded in the review's two LOW suggestions: case-insensitive digest compare, and a wiring-invariant test ( |
Closed
3 tasks
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
The embedding model verifies its GGUF against a pinned SHA-256 before native llama.cpp loads it (ADR-058); the chat/LLM model had no equivalent. Chat models are verified at download time, but a model correctly downloaded and then swapped/tampered on disk was loaded without re-verification — the same post-install tamper window the embedding load gate closes, into C++ with full authority (integrity + memory-safety surface).
Change
nlp-engine/chat/mod.rs—load_model(model_path, expected_sha256: Option<&str>). After theexists()check and beforebackend()/load_from_file, when a digest is present it verifies the on-disk file and returnsChatError::IntegrityErroron mismatch.Noneis the documented escape hatch for a user-supplied / non-catalog model (loads with a warning — nothing to verify against).nlp-engine/chat/error.rs— newChatError::IntegrityError.nlp-engine/config.rs— extracted a genericverify_file_sha256(path, expected)fromverify_model_integrity(which now delegates to it); comparison is case-insensitive so a correctly-pinned digest can't be refused over casing.agent/model_manager.rs—expected_sha256_for_filename(filename)resolves the pinned digest from the catalog by GGUF basename.agent/inference.rs—LlamaChatInferenceEngine::loadresolves the digest from the model file's basename and passes it down, preserving theagent → nlp-enginedependency direction (nlp-engine can't import the catalog).The digest lookup keys off the same
entry.filenamethatmodel_path()builds the load path from, so a catalog model's basename always resolves toSome(digest)— a wiring-invariant test guards that. The daemon load surface takes amodel_id(never an arbitrary path), so theNonebranch is unreachable today (future-proofing).Acceptance criteria
load_from_file, reusing the digests inmodel_manager.rsChatError::IntegrityError, mirrorsEmbeddingError::IntegrityError)Noneescape hatch: load with a warning)Tests
verify_file_sha256accepts match / rejects mismatchexpected_sha256_for_filenameresolves a catalog filename /Nonefor unknownload_modelreturnsIntegrityErroron a mismatched digest before native loadnlp-engine 99 / agent 301 lib tests pass; clippy clean; full pre-push gate (test:all +
cargo build --bin nodespaced+ test:e2e +cargo test -p nodespace-app) green. Independent adversarial review: no bypass / correctness bug / regression.Closes #1729.
Context: Threat T9, ADR-058 (Model Artifact Integrity Verification). Companion to the embedding-model load gate (#1715).