Model and supply-chain risk
Your AI feature depends on far more than your own code: model weights downloaded from a hub, a hosted API whose model changes under you, tokenizers, datasets, fine-tuning libraries, MCP servers and inference engines. Any of these can be malicious, tampered with, or silently changed. This doc covers how to treat models and AI artefacts with the same supply-chain discipline you already apply to packages and containers.
Why it matters
Supply Chain is LLM03 and Data and Model Poisoning is LLM04 in the OWASP Top 10 for LLM Applications 2025. The concrete threats are well documented:
- Malicious weight files. PyTorch's default checkpoint format uses Python pickle, and the Hugging Face docs are blunt that loading a pickle file can execute arbitrary code. Scanners help but can be bypassed; academic work and 2025 CVEs showed malicious files evading blocklist-based scanners.
- Tampered or swapped models. A repository can be updated after you evaluated it, or a look-alike repo can impersonate a popular one.
- Poisoned data and backdoors. A model or dataset can behave normally until a trigger phrase appears.
- Hosted model drift. An API alias can point to a new snapshot with different behaviour, breaking your evals' assumptions.
- Tooling and plugins. Agent frameworks and MCP servers run code and inject text into prompts.
How it works
Four controls cover most of the risk.
Safe formats. Prefer safetensors, which stores only tensors and cannot carry executable code. An external security audit published by Hugging Face and EleutherAI concluded that loading safetensors files is safe, and safetensors is now installed and used by default in Transformers. Refuse pickle-based checkpoints from untrusted sources, and never set trust_remote_code=True for code you have not reviewed.
Pinning. Pin hub downloads to an exact commit revision, not a branch, and pin hosted API models to dated or snapshot IDs rather than moving aliases where the provider offers them.
Signing and provenance. The OpenSSF model-signing project (v1.0, April 2025) signs and verifies models of any format and size, including directory trees, using Sigstore keyless signing by default, with signatures recorded in a public transparency log. Verify signatures before loading, and sign your own fine-tuned artefacts.
Documentation. Model cards (Hugging Face's format) and dataset cards record intended use, training data, evaluation results and limitations. An AI bill of materials (AIBOM) lists every model, dataset, adapter and library version in a deployed system.
Rendering diagram…
Reference architecture
The cleanest pattern is an internal model registry as the only source production can load from. Nothing pulls directly from a public hub at runtime.
Rendering diagram…
Treat fine-tuning outputs the same way: your trained adapter should be signed, carry a model card linking to its dataset version and eval results, and enter the registry through the same gate.
Code
Pin a Hugging Face download to a commit, accept only safetensors and config files, and verify an OpenSSF model signature before loading. snapshot_download with revision and allow_patterns is the documented huggingface_hub API, and model_signing verify is the project's CLI.
import subprocess
from huggingface_hub import snapshot_download
from safetensors.torch import load_file
REPO = "my-org/support-classifier"
COMMIT = "3f9c2a1e0b7d4c6a8e5f1b2d3c4a5e6f7a8b9c0d" # exact commit, reviewed in intake
path = snapshot_download(
repo_id=REPO,
revision=COMMIT,
allow_patterns=["*.safetensors", "*.json", "tokenizer*", "model.sig"],
)
# keyless Sigstore verification: signer identity and OIDC issuer must match
subprocess.run(
["model_signing", "verify", path,
"--signature", f"{path}/model.sig",
"--identity", "release-bot@my-org.iam.gserviceaccount.com",
"--identity-provider", "https://accounts.google.com"],
check=True,
)
weights = load_file(f"{path}/model.safetensors") # no pickle, no code execution
Check the flags against the model_signing version you install; the CLI has evolved since v1.0.
Trade-offs and pitfalls
- Scanners are not a guarantee. Pickle scanning catches known patterns; safe formats remove the class of bug.
trust_remote_codeis a code dependency. Custom modelling code from a repo runs with your process's privileges. Vendor it and review it.- Moving aliases. "latest" model names on hosted APIs make evals stale. Pin, and re-run evals when you upgrade deliberately.
- Licences are supply chain too. Open-weight licences vary on commercial use, attribution and acceptable use. Record them in the AIBOM.
- Backdoors survive fine-tuning. Evaluate third-party base models for unexpected behaviour on trigger-like inputs before building on them.
- Forgotten dependencies. Inference servers, tokenizers and agent plugins are part of the chain. Track their versions and advisories.
Checklist
- Load only safetensors (or other non-executable formats) from external sources.
- Pin hub downloads to commits and hosted models to snapshot IDs.
- Verify signatures and hashes before loading; sign your own artefacts.
- Route all production models through an internal registry with an intake gate.
- Keep model cards, dataset cards and an AIBOM for every deployed system.
- Review any
trust_remote_codecode and third-party MCP servers. - Subscribe to advisories for models, libraries and inference engines you use.