AI/ML Security

The AI Model Repository Is Your New Dependency Supply Chain

Jul 31, 20265 min read

Your security team reviews npm packages before they go to production. Probably. You have processes around pip dependencies, or at least aspirations toward them. You know the SolarWinds lesson: the build pipeline is now an attack vector, and third-party software you trust is how attackers get in.

Now your data science team is pulling models from Hugging Face.

The model files land in your infrastructure, get loaded into memory, and run inference on your production data. Nobody filed a software intake form. Your dependency management tooling does not know they exist. Security has not seen them.

This is your new supply chain problem, and most organizations have not noticed it yet.

The File That Runs Code When You Open It

The dominant format for sharing machine learning models is still the pickle file. Python's pickle module serializes and deserializes Python objects, and a serialized model is just a Python object. Loading a pickled model file executes whatever Python code the serializer embedded in it.

This is not a theoretical vulnerability. It is a design characteristic. The Hugging Face model hub has shipped deliberately malicious models that executed code on load. Researchers have demonstrated that a pickle-based model file can function as a remote code execution payload wrapped in something that looks like a transformer architecture. There have been real, documented cases - not proof-of-concept demonstrations - of models on public registries that ran malicious code when loaded.

The safer alternatives exist. SafeTensors is a format specifically designed to store only tensor data with no embedded execution path. ONNX serializes computation graphs rather than Python objects. But the ecosystem has not fully migrated, plenty of models still ship as pickle files, and many practitioners load them without thinking about what that means.

When your team calls torch.load on a pickle file, they are executing code from whoever packaged that file.

The Public Repository Has Minimal Scrutiny

Hugging Face has grown into the default distribution point for pre-trained models, with hundreds of thousands of models publicly available. The platform runs automated scanning and has improved its safety processes over time. It is also a platform where anyone can upload a file and where volume outpaces thorough review.

The security model resembles early package registries before npm and PyPI supply chain incidents forced more scrutiny. Malicious packages sat in PyPI for years before discovery. Typosquatted packages with names close to popular libraries have compromised developer environments repeatedly. The same dynamics apply here: a model named something close to a popular foundation model, uploaded by an account with no history and a few fabricated stars, can sit in the registry and accumulate downloads.

What Hugging Face provides is a place to find models. It does not provide assurance that the model does what its README claims, contains no hidden functionality, or was produced by who it says it was.

Backdoors Are Harder to Detect Than Malware

The executable-on-load risk in pickle files is the obvious attack vector. The subtler problem is intentional model behavior that does not show up in the weights, the architecture, or any normal evaluation.

A backdoored image classification model might perform exactly as advertised on standard test sets while being trained to misclassify specific inputs when a particular trigger pattern is present. A text model might behave normally except when it encounters a specific token sequence that causes it to produce attacker-controlled output. These backdoors survive fine-tuning in many cases, which means pulling a backdoored base model and fine-tuning it on your own data does not eliminate the problem.

Detecting backdoor attacks on neural networks is an active research area precisely because it is hard. Standard evaluation does not surface them. The model passes your accuracy benchmarks. The backdoor activates only on inputs crafted to trigger it.

For most enterprise use cases, the realistic attacker is not planting backdoors in public models hoping your specific organization downloads them. But for high-value targets and use cases where model behavior integrity matters - fraud detection, content moderation, medical screening - the threat model is real enough to take seriously.

What a Reasonable Posture Looks Like

The goal is not to stop using public models. Pre-trained foundation models represent an enormous practical advantage that no organization is going to give up. The goal is to treat model acquisition with the same skepticism you apply to open source software dependencies.

Start with provenance. Official releases from organizations like Meta, Mistral, Google, and major research institutions should come from verified sources with checksum verification. A model that claims to be a well-known architecture but was uploaded by an anonymous account three weeks ago deserves more scrutiny than the official release.

Load models in isolated environments before they get anywhere near production data. A model that executes code on load is much less interesting if it runs in a sandboxed container with no network access and no credentials to steal.

Prefer safer serialization formats when you have the choice. If a model is available in SafeTensors format, use it. If it is only available as a pickle file from a poorly-established source, that is information about the risk you are accepting.

Apply the same controls to model files that you apply to container images: artifact signing where available, storage in a controlled internal registry rather than pulling from public sources at runtime, and audit logging that tells you which version of which model is running in which environment.

The Assumption Worth Fixing

The implicit assumption underneath most enterprise AI deployment is that the security challenge lives in the application layer - prompt injection, output validation, access controls on what the model can do. Those are real problems.

The model file itself is also a risk vector. It is code your team downloaded from a public repository and executed in your environment. Your software composition analysis tooling probably does not know it is there. Your vulnerability management process has no record of it.

That gap between how your organization treats application dependencies and how it treats model files is where the next supply chain incident is waiting.