Insecure model supply chain: weights, pickles, and model hubs
Downloaded models are code and data from someone else. Why pickle-based weight files can execute code on load, how to prefer safetensors, pin revisions, scan artifacts, and record model provenance.
Diagram
Loading a model from a public hub
Step 1 of 4
Download
A notebook pulls a model by name only.
model = AutoModel.from_pretrained("someorg/sentiment-small")The example on the open step is one illustration, or the fix you can paste into an application you own.
What this page is made of
3 pieces. Each one says what fails, who is affected, what you would notice, and what you change.
Pickle loading
- What fails
- Python pickle can execute code during load.
- Who is affected
- The machine and credentials loading the model.
- What you would notice
- torch.load without weights_only, or pickle.load on downloaded files.
- What you change
- Use safetensors, or weights_only=True, and scan pickles before use.
Unpinned revisions
- What fails
- Model names point at whatever the repository holds now.
- Who is affected
- Every pipeline that pulls the model.
- What you would notice
- from_pretrained calls with no revision.
- What you change
- Pin revisions and mirror approved models internally.
Provenance
- What fails
- Teams cannot answer which model version produced a result.
- Who is affected
- Investigations and audits.
- What you would notice
- No record of model source, hash, and license.
- What you change
- Keep a model register like an SBOM.
Scanning artifacts
Open-source scanners such as picklescan and modelscan inspect pickle opcodes for imports that should not be there. Run them in CI on any model before it enters an internal registry.
$ modelscan -p ./models/sentiment-small Scanning ./models/sentiment-small/pytorch_model.bin --- Summary --- No issues found. $ ls ./models/sentiment-small config.json model.safetensors pytorch_model.bin
Check yourself
Recognition and the fix. Nothing here is a procedure.
Why prefer safetensors over pickle-based weights?
Sibling techniques
Pages at the same depth, plus a lab and a glossary card for this one.
This page stands on its own. The lab and the glossary card are the next reading.