A typical machine learning project today starts in a notebook. Within minutes, it imports a deep learning framework, a dozen data science libraries and a pre-trained model downloaded from a model hub, and loads a public dataset. It is a remarkably productive workflow. It also pulls a large, mostly unvetted software supply chain into systems that may end up in production.
What the ML supply chain includes
Python and system packages
ML frameworks sit on top of hundreds of transitive dependencies: numerical libraries, data loaders, image and audio codecs, and native extensions compiled from C and C++. Many are installed with pip install from a notebook cell, often without version pins. The Python Package Index has repeatedly had to remove typosquatted packages designed to catch users who mistype popular names.
ML frameworks
TensorFlow, PyTorch and similar frameworks are large, complex codebases with their own security advisories: TensorFlow publishes security advisories for issues such as memory corruption triggered by malformed inputs or model files. Framework versions in ML projects often lag far behind the latest releases.
Pre-trained models
Transfer learning has made pre-trained models central to modern ML. Models are downloaded from model hubs, research repositories and colleagues' shared drives. Two risks stand out:
- Unsafe serialisation. Many model files are saved with Python's
pickleformat, which can execute arbitrary code when loaded. Loading an untrusted model file is equivalent to running untrusted code. - Backdoors. Research such as BadNets has shown that a model can be trained to behave normally on standard inputs but misbehave when a specific trigger appears. Standard accuracy evaluation will not reveal it.
import torch
# torch.load uses pickle: only load model files from sources you trust
state = torch.load("downloaded_weights.pt", map_location="cpu")
# Prefer loading weights into a known architecture over unpickling whole model objects,
# and verify a published checksum before loading anything.Datasets
Public and scraped datasets may be mislabelled, biased, licensed restrictively, or deliberately poisoned. Datasets downloaded by URL at training time can change without notice.
Tools and infrastructure
Notebook servers, experiment trackers, model servers and data pipeline tools are part of the chain too. Exposed notebook servers without authentication have been abused for cryptocurrency mining and data theft.
Why ML makes supply-chain hygiene harder
- Speed of experimentation: notebooks encourage installing and trying packages quickly.
- Research culture: code and models are shared informally, with less emphasis on provenance.
- Environment drift: "it worked on my notebook" environments are hard to reproduce.
- Large binary artefacts: model files and datasets are not reviewed like code.
Bringing ML under supply-chain control
flowchart LR
subgraph Controls
P[Pin & lock<br/>packages] --> X[Internal package<br/>& model proxy]
X --> S[Scan<br/>dependencies & images]
S --> V[Verify<br/>checksums & sources]
V --> R[Record provenance<br/>code, data, model versions]
end
NB[Notebook experiments] --> Controls
Controls --> Prod[Production training<br/>& serving]Pin and lock dependencies. Move from notebook pip install cells to locked environment files (for example requirements.txt with hashes, poetry.lock or conda lock files) before anything reaches production.
# Generate a fully pinned, hashed requirements file and install exactly that
pip-compile --generate-hashes requirements.in
pip install --require-hashes -r requirements.txtUse internal mirrors for packages, models and datasets, so production pipelines never pull directly from public sources at runtime.
Scan dependencies and containers used for training and serving, and keep ML frameworks patched.
Vet pre-trained models. Prefer models from trusted publishers, verify checksums, avoid unpickling untrusted files, and evaluate models on your own data, including tests for unexpected behaviour.
Record provenance. For each production model, record the code commit, dependency versions, dataset versions and sources, and base model. This makes models reproducible and incidents investigable.
Secure the tooling. Put authentication in front of notebooks, experiment trackers and model servers, and never expose them directly to the internet.
The bottom line
Machine learning inherits the entire open-source software supply chain and adds pre-trained models and datasets on top. The same disciplines that protect other software (pinning, mirroring, scanning, verifying and recording provenance) apply to ML, and they need to be applied deliberately, because ML's experimental culture makes them easy to skip.
Our secure code review and application security testing teams review ML projects' dependencies, model handling and infrastructure.