Models, data and the supply chain

Unit 5 of 5 in Securing LLM applications.

You will be able to vet a model and its files before use, gate them in a build and explain how poisoned data and documents reach a model.

Lesson

What you download is part of your application

OWASP's supply chain entry says LLM supply chains are susceptible to vulnerabilities at many points: third-party libraries, base models and fine-tuned copies, datasets and plugins. Its example scenarios include a vulnerable Python library, a model tampered with directly and republished to spread misinformation, and a popular model fine-tuned by an attacker. The page's first advice is the ordinary one: vet your data sources and suppliers, scan and patch components, and keep an inventory.

It also adds something specific to models. Apply AI red teaming and evaluation when you choose a third-party model, especially for your own use case, because models can be fine-tuned to bypass published benchmarks. A good score on a public test is not proof of a model's safety for your task.

Why a model file can run code

The Hugging Face documentation explains a hazard in the file format. Pickle is a widely used Python serialization format, and the default for PyTorch model weights. Loading a pickle file can execute arbitrary code: a pickle is a stack of instructions, and some instructions import modules and call functions with given arguments. The page's summary is the standard advice, do not unpickle data from untrusted sources.

Its mitigations: load files from users and organizations you trust, rely on signed commits (which show who a file came from, not that it is safe), load weights from formats that do not execute code, and note that the Hub shows the list of imports inside a pickled file. It points to safetensors as a simple serialization format for weights. The labs in this unit let you read such a file, see the difference, and reject a malformed one before loading it.

Verify what you got: pins, hashes, signatures and a bill of materials

OWASP recommends using models only from verifiable sources and using third-party integrity checks with signing and file hashes to make up for the lack of strong model provenance, and code signing for externally supplied code. It also recommends an up-to-date inventory, a software bill of materials, noting that AI and machine learning bills of materials are an emerging area where OWASP's CycloneDX is a place to start, and a licence inventory for models, tools and datasets.

The Sigstore model-transparency project aims at the same goal: strengthen the machine learning supply chain the way the traditional software supply chain is strengthened, with verifiable claims about the integrity and provenance of a model, so users can check for themselves instead of trusting the trainer. It supports signing through Sigstore, which avoids managing key material yourself, and traditional signing with public keys. In practice: pin a model to an exact commit, record the hash of each weights file, sign what you publish, verify what you consume, and fail the build when any of these drift.

Data that feeds the model

Models are shaped by data, and applications feed them data at run time. The cheat sheet on prompt injection describes retrieval poisoning: adding harmful documents to a retrieval store, or manipulating what retrieval returns so attacker-controlled content reaches the model. Its defences for external content are to sanitize remote content, check documents for hidden text before the model reads them, and send anything the check cannot read fully to human review or give the model only the visible text, marked incomplete.

At training time, NIST's taxonomy lists data poisoning among the attack classes it covers. OWASP adds that anomaly detection and adversarial robustness tests on supplied models and data can help detect tampering and poisoning, noting these techniques are emerging and may be easier to include in red teaming exercises than in everyday pipelines. Be honest in your own documents about which of these you actually do.

Put the checks in the pipeline

This section is our own synthesis of the sources above, not a quote. Treat a model like any other dependency: only fetch from an allow-list of sources, pin to an exact version and hash, scan files before loading, prefer a format that cannot run code, lint the model card and licence, keep a bill of materials and fail the build when it drifts, then re-run your own security tests (unit 2) against the exact files you will deploy. Each step is cheap and automatic, and each answers a different question: where did it come from, is it what I think it is, can it run code, may I use it, and does it behave under my tests.

Key points

Sources

Practice in the labs

Scan, pin, sign and inventory a model, lint its licence, check generated code for invented packages and see how a poisoned knowledge base is defended. All labs use small demo files and run on your machine.

Knowledge check

  1. Why can loading a pickle-based model file be dangerous? Answer: Pickle can import modules and run code when it is loaded. The Hugging Face documentation explains that a pickle is a set of instructions, some of which import modules and call functions, so loading an untrusted pickle can execute arbitrary code.
  2. A model repository commit is signed by a publisher you trust. What does the signature show? Answer: Where the file came from, not that the file is safe. The Hugging Face page says a signed commit does not guarantee the file is safe but does guarantee its origin, so you still need other checks.
  3. Why pin a model to a commit and record its file hashes? Answer: So you can detect any change to what you deploy. OWASP recommends integrity checks with signing and file hashes to compensate for weak model provenance. A pin and a hash make a silent change visible.
  4. A model scores well on a public safety benchmark. Is it safe for your product? Answer: Not proven: models can be tuned to bypass published benchmarks, so test it on your own use case. OWASP's supply chain page says models can be fine-tuned to bypass published benchmarks and recommends extensive red teaming and evaluation for the use cases you plan.

Back to the syllabus or see all classes.

Related