Model & data supply chain

In one sentence

Every model file, dataset, package and MCP server you pull is code or influence you didn't write: load weights as safetensors, pin hashes, scan and sign artifacts, serve only from a vetted internal registry.

Analogy: A hospital pharmacy only stocks sealed drugs from approved suppliers, with lot numbers it can recall. It never accepts an unlabelled vial just because the contents look right.

Production pulls only from the internal registry; scanning catches malicious code, while evals are the only check on malicious behavior.

How it works

  • PyTorch .bin checkpoints are pickle, so loading a model can run an attacker's script.
  • Poisoning needs little: ~250 crafted documents backdoored models from 600M to 13B parameters, regardless of size.
  • Slopsquatting: attackers register package names LLMs hallucinate; one study found ~20% of suggested packages didn't exist.
  • MCP servers run with your agent's credentials, and a rug pull changes a tool after you approve it.
  • An AI-BOM lists every model, dataset and tool version, so one query finds the services a CVE hits.

Check yourself

Answer to mark it learned; your answers aren't scored.

A data scientist found a sentiment model from an unknown Hugging Face account. torch.load refused its pickled .bin, so they set weights_only=False, it loaded, and they ask you to approve it for production. Your call?

Go deeper

Full explanation

Your AI system runs on artifacts you didn't build: weights, datasets, Python and npm packages, and now MCP servers and tools. Each is an attack path:

  • Malicious model files. PyTorch .bin/.pt checkpoints are pickle, and unpickling can execute arbitrary code: loading a model can mean running the attacker's script. safetensors stores only a JSON header plus raw tensors, so loading runs no code. JFrog found ~100 malicious models on Hugging Face in 2024.
  • Poisoned data. A few hundred crafted documents in pretraining or fine-tuning data can plant a trigger; scraped datasets point at URLs whose expired domains anyone can buy.
  • Backdoored "sleeper" models. Weights that behave normally until a trigger appears. Anthropic's Sleeper Agents paper showed such backdoors surviving SFT, RLHF and adversarial training.
  • Compromised or fake dependencies. Typosquats, dependency confusion (PyTorch's torchtriton, 2022), hijacked releases (Ultralytics, 2024) and slopsquatting: registering package names that LLMs hallucinate.
  • Malicious MCP servers and tools. A tool runs with your agent's credentials and its description lands in the prompt (Prompt injection (direct & indirect)); a "rug pull" changes it after approval.

The fix is classic supply-chain hygiene: provenance, hash pinning, scanning (ModelScan, picklescan), signing (Sigstore-based OpenSSF model signing), an AI-BOM listing every model, dataset and tool version, and a vetted internal registry as the only source production can pull from.

Code Load pinned, verified weights without running pickle
pythonLoad pinned, verified weights without running pickle
import hashlib
import torch
from huggingface_hub import hf_hub_download
from safetensors.torch import load_file

# HF_ENDPOINT points at the internal registry (e.g. an Artifactory mirror)
REPO = "acme/support-llm-ft"
REVISION = "9f2c1e7b4a..."      # a commit SHA, never a branch like "main"
EXPECTED_SHA256 = "3b1d..."      # recorded in the AI-BOM at approval time

def sha256_file(path: str) -> str:
    h = hashlib.sha256()
    with open(path, "rb") as f:
        for block in iter(lambda: f.read(1 << 20), b""):  # stream multi-GB files
            h.update(block)
    return h.hexdigest()

path = hf_hub_download(REPO, "model.safetensors", revision=REVISION)
if sha256_file(path) != EXPECTED_SHA256:
    raise RuntimeError("weights differ from the reviewed artifact")

# JSON header + raw tensors: parsing it executes no code
state_dict = load_file(path)

# Legacy pickle checkpoint? Allow plain tensors only, no arbitrary objects
legacy = torch.load("old.pt", weights_only=True)

# transformers: refuse repo-supplied Python and pickle weights
# AutoModel.from_pretrained(REPO, revision=REVISION,
#                           use_safetensors=True, trust_remote_code=False)
Real example

A data scientist downloads a sentiment model from an unknown Hugging Face account and loads its pickled .bin with weights_only=False to silence an error. The pickle's __reduce__ opens a reverse shell from a laptop holding cloud credentials. With controls in place, the request goes through the internal registry instead: ModelScan flags an os.system call in the pickle, the import is rejected, and the team uses the official safetensors release, pinned by commit SHA and recorded in the AI-BOM. Months later a CVE hits a tokenizer library, and one AI-BOM query lists the 4 affected services.

Trade-offs +3 · −3

+ You gain

  • Blocks the cheapest attacks (code execution on load, typosquats) at almost no cost.
  • An AI-BOM turns "are we affected?" from a week of archaeology into one query.
  • Pinned hashes make builds reproducible, which also makes evals and audits trustworthy.

− You pay

  • Scanners catch malicious code, not malicious behavior: a backdoor lives in the weights.
  • A vetted registry slows teams who want the model released this morning.
  • Provenance for third-party datasets and API models is often unavailable; you rely on vendor attestations.

Use it when

Always, scaled to risk: any team that downloads open weights, fine-tunes on external data, installs AI packages or lets agents connect to third-party MCP servers.

Avoid it when

There is no opt-out, only proportionality: a hackathon prototype on a closed API needs pinned dependencies, not a signed internal model registry.

Numbers to know 5
  • ~250 poisoned documents were enough to backdoor models from 600M to 13B parameters, regardless of size (Anthropic, UK AISI, Turing Institute, Oct 2025).
  • Poisoning 0.01% of LAION-400M via expired domains would have cost ~$60 (Carlini et al., 2023).
  • A 2024 study found ~20% of packages suggested in LLM-generated code did not exist: names an attacker can register.
  • PyTorch 2.6 (Jan 2025) made torch.load(weights_only=True) the default.
  • OWASP LLM Top 10 (2026): LLM04 Supply Chain, LLM05 Data and Model Poisoning (LLM03 and LLM04 in the 2025 edition).
Common pitfalls 4
  • trust_remote_code=True on an unreviewed Hugging Face repo: it runs the repo's Python on your machine.
  • Pinning to a branch or tag like main instead of a commit SHA, so the weights change under you.
  • Treating a clean ModelScan report as proof the model is safe; behavior needs evals and red-teaming.
  • Letting agents install any MCP server from a public list, running with production credentials.
Interview questions 3

Answer out loud first, then reveal.

A team wants to fine-tune a popular open model from Hugging Face. What controls do you require?Show answer

I treat it like any third-party binary. First provenance: official org, license, known training data. Then it goes into quarantine: safetensors only, trust_remote_code off, a ModelScan pass, the commit SHA pinned and the hash recorded in our AI-BOM. It's signed and published to the internal registry, the only place training and serving can pull from. Because no scan can see a backdoor in the weights, it also runs our eval suite and red-team prompts before any traffic.

How do you defend an agent platform against malicious MCP servers?Show answer

An MCP server is code plus prompt text running with my agent's permissions, so it's both a dependency and an injection vector. I allow only servers from an internal allowlist, pinned by version and hash, so a rug pull that edits tool descriptions breaks the pin. They run sandboxed with least-privilege, per-user credentials, never a shared admin token. Tool descriptions are reviewed like code, and high-impact actions need human approval. The trade-off is slower onboarding of new tools, which I accept.

Can you detect a backdoored model?Show answer

Not reliably, and I say that upfront. Sleeper Agents showed backdoors surviving safety training, and the trigger can be any string. So I rely on provenance, meaning who trained it and on what data, and on limiting blast radius: the model never holds authority, its outputs pass deterministic checks, and agents run with least privilege. Detection techniques like trigger search or activation probes exist, but I treat them as research, not as a control I'd sign off on.