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.

Lesson 49 of 69 · 11 min read · practice only with authorization

Diagram

Loading a model from a public hub

Follow the path. One example at a time.

Step 1 of 4

Download

A notebook pulls a model by name only.

Illustration: Download
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.

  1. 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.
  2. 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.
  3. 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.

1 / 3

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.

Practice

  1. LabControl benchA failure is described. Choose the control that changes the outcome.

Glossary

  1. CardInsecure model supply chainWeights, plugins, or prompts are pulled from a source you do not pin.