Skip to content

Build-time model download (scripts/download-models.ts) skips SHA-256 verification #1715

Closed

Description

@malibio

Summary (S-01, Critical / P0 — release-blocking)

Model artifacts are downloaded with curl -L and no SHA-256 verification — no pinned digest, no post-download comparison, no load-time check. Because the download runs at build time, a substituted (compromised upstream, redirect hijack, MITM on a CI runner, malicious mirror) model is then code-signed and notarized as authentic and shipped to every user. The GGUF is parsed by native C++ (llama.cpp) inside the daemon, so a hostile artifact is both an integrity failure and a memory-safety attack surface running with full daemon authority.

The security posture doc previously claimed "SHA-256-pinned model downloads" — it was aspirational. This is the one unmet leg of the T9 supply-chain hardening bar.

Evidence

  • scripts/download-models.ts:16 — MODEL_URL = https://huggingface.co/.../resolve/main/${MODEL_FILE}
  • scripts/download-models.ts:38 — curl -L --progress-bar -o ${MODEL_PATH} ${MODEL_URL} (no digest anywhere in the path)
  • packages/nlp-engine/src/config.rs:70 — resolves the first on-disk *.gguf and loads it with no integrity check

Acceptance criteria

  • Pin an expected SHA-256 next to MODEL_URL (and a matching constant at the Rust load site)
  • After download, compute the digest and fail hard + delete the file on mismatch
  • Verify the on-disk model against the pinned digest at load time; refuse to load on mismatch (closes the post-install tamper window — see S-19)
  • Download over HTTPS with normal cert validation (the digest remains the authoritative gate regardless of redirect target)
  • Rotating the model updates the pinned digest in the same change

Context / implementation reference

  • Decision + verification contract: ADR-058 — Model Artifact Integrity Verification (nodespace-docs/decisions/058-model-artifact-integrity-verification.md)
  • Threat T9 and the v1 hardening bar: nodespace-docs/architecture/security-posture.md
  • Consolidated register (S-01, S-19): nodespace-docs/architecture/security-review-2026-07.md

Activity

  1. malibio commented on Jul 23, 2026

    @malibio
    CollaboratorAuthor

    Duplicate of #1497 (same finding, filed 2026-07-05, already assigned). Folded the ADR-058 reference and the scripts/download-models.ts detail into #1497.

  2. changed the title [-]Model download has no SHA-256 integrity verification (supply-chain, Critical)[/-] [+]Build-time model download (scripts/download-models.ts) skips SHA-256 verification[/+] on Jul 23, 2026
  3. malibio commented on Jul 23, 2026

    @malibio
    CollaboratorAuthor

    Reopened — this is NOT a duplicate of #1497 after all

    I closed this as a duplicate of #1497, but on verifying the code that was wrong. The two cover different download paths:

    So the runtime path is hardened; the build/bundle path is not. That's the Critical gap.

    Acceptance criteria

    • scripts/download-models.ts verifies the downloaded artifact against a pinned SHA-256 (reuse the same pinned digests already in model_manager.rs), fail-hard + delete on mismatch
    • Load-time verification of the on-disk GGUF (companion; see ADR-058)

    Context

    • ADR-058 — Model Artifact Integrity Verification (nodespace-docs/decisions/058-model-artifact-integrity-verification.md)
    • Threat T9: nodespace-docs/architecture/security-posture.md
  4. mstomar125 commented on Jul 24, 2026

    @mstomar125
    Contributor

    ✅ Completed — merged in PR #1730

    Model-artifact integrity is now enforced at both ends of the build-time embedding-model path (ADR-058, Threat T9).

    Build-time (scripts/download-models.ts): the URL is pinned to HF commit 0188c9bf…, MODEL_SHA256 is pinned, curl -fL --proto =https fails hard on HTTP errors, and the artifact is stream-verified after download (and any pre-existing file is re-verified) — on mismatch the file is deleted and the script throws, so an unverified model can never be bundled/signed/notarized.

    Load-time (packages/nlp-engine): EmbeddingService::initialize() computes the on-disk GGUF's SHA-256 and refuses to load on mismatch before LlamaModel::load_from_file, closing the post-install tamper window. Added EMBEDDING_MODEL_SHA256, compute_file_sha256 (64 KB streaming), verify_model_integrity, EmbeddingError::IntegrityError, and the sha2 dep.

    Acceptance criteria — all met

    • Pinned SHA-256 next to MODEL_URL + matching constant at the Rust load site
    • Post-download digest compare, fail hard + delete on mismatch
    • Load-time verification, refuse to load on mismatch
    • HTTPS with normal cert validation (digest is the authoritative gate)
    • Model rotation updates the pinned digest in the same change (contract documented in both the script and config.rs)

    Verification

    • Pinned digest 3e24342164b3d94991ba9692fdc0dd08e3fd7362e0aacc396a9a5c54a544c3b7 matches the authoritative HF LFS metadata for the pinned commit and the shipped local model.
    • Live run of the script verified the real 146 MB model in ~0.2 s.
    • New Rust unit tests green (NIST sha256("abc") vector, mismatch rejection, unreadable-file error, digest-format invariant); cargo clippy clean; cargo test --lib green; no test regressions (integration tests skip when the model is absent / use the real default config).
    • Independent adversarial review: CONFIRMED-GOOD across all 7 scrutiny points.

    Follow-up filed

    Note (deliberate)

    Only the pinned Q8_0 bytes pass the load gate; resolve_model_path's .f16/.gguf fallbacks and a custom model_path still resolve but are rejected at load if they aren't the pinned artifact — documented on resolve_model_path so nothing but the pinned model reaches native llama.cpp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions