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
- Models, datasets, libraries and plugins are part of your supply chain; vet suppliers and keep an inventory.
- Pickle-based model files can run code when loaded; prefer formats that cannot, and load only from trusted sources.
- Pin to a commit, record file hashes, sign what you publish, verify what you consume, and keep a bill of materials.
- Poisoned documents can reach a model through retrieval; check documents for hidden text and sanitize remote content.
- Public benchmark scores do not replace your own red teaming and tests for your use case.
Sources
- OWASP GenAI Security Project: LLM03:2025 Supply Chain
- Hugging Face Hub documentation: Pickle Scanning
- Sigstore model-transparency: supply chain security for ML (project page on GitHub)
- OWASP Cheat Sheet Series: LLM Prompt Injection Prevention
- NIST AI 100-2 E2025: Adversarial Machine Learning: A Taxonomy and Terminology of Attacks and Mitigations
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.
- Gate every model your team downloads: scan a model folder with ModelScan and fail the build on unsafe code: You write a gate that passes a clean model, fails a trapped one and fails an empty folder, with a saved report.
- Scan an ML model for malicious pickle code (before it runs code on you): You see a harmless marker file created by a naive load, flag the same file with two scanners, then load safely from a format with no code path.
- Read a safetensors model file by hand and reject a malformed one before loading it: You write a validator that accepts a good file and rejects two malformed ones, and explain why a pickle could not be checked this way.
- Pin a Hugging Face model to a commit and verify its file hashes before use: You write a pin file with the full commit and a file hash, and a verify script that fails after you change one byte.
- Sign and verify an ML model with Sigstore: You sign a model file, verify it, then see verification fail for a changed byte and a wrong signer identity.
- Write an AI bill of materials for a model with CycloneDX and fail the build when it drifts: You write and validate an AI bill of materials and fail a gate when the model file or its licence entry changes.
- Lint the model card and license of every model you download, and fail the pipeline on a bad one: You write a linter that blocks missing or restrictive licences and flags unusual ones for review.
- Catch hallucinated package names in LLM-generated code before you pip install them (slopsquatting defence, stub assistant): You measure how often model-written code names packages that do not exist and build a gate that blocks them before install.
- Poison a RAG knowledge base (PoisonedRAG) and defend it: flip an answer with a few crafted documents, measure the attack success rate, then drive it back down (free, local, deterministic — no API key): You measure how a poisoned document changes a retrieval answer in a small local setup, then add defences and re-measure.
Knowledge check
- 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.
- 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.
- 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.
- 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
- Securing LLM applications
- Gate every model your team downloads: scan a model folder with ModelScan and fail the build on unsafe code
- Scan an ML model for malicious pickle code (before it runs code on you)
- Read a safetensors model file by hand and reject a malformed one before loading it
- Pin a Hugging Face model to a commit and verify its file hashes before use
- Sign and verify an ML model with Sigstore
- Write an AI bill of materials for a model with CycloneDX and fail the build when it drifts
- Lint the model card and license of every model you download, and fail the pipeline on a bad one
- Catch hallucinated package names in LLM-generated code before you pip install them (slopsquatting defence, stub assistant)
- Poison a RAG knowledge base (PoisonedRAG) and defend it: flip an answer with a few crafted documents, measure the attack success rate, then drive it back down (free, local, deterministic — no API key)
- All classes
- Free cyber labs