Why Hugging Face Model Hacks Are Getting Out Of Control

Why Hugging Face Model Hacks Are Getting Out Of Control

Someone uploaded a poisoned AI model to Hugging Face, and thousands of developers downloaded it before anyone sounded the alarm.

It wasn't a sci-fi movie scenario. Nobody created a sentient machine that decided to overthrow humanity. The reality is far more boring—and far more dangerous. Attackers hijacked the open-source infrastructure that powers modern software, dropping backdoors into neural network weights and stealing API tokens right off developer machines.

If you build software with open-source AI models, you've probably assumed that downloading a popular model checkpoint is as safe as pulling a Python package. You'd be wrong.

How Malicious Code Sneaks Into Popular AI Hubs

Most developers think of an AI model as just a giant list of floating-point numbers. In reality, older formats like PyTorch .pt or .bin files rely on Python's pickle library to serialize data.

Pickle is dangerous. By design, unpickling an object can execute arbitrary Python code on your CPU the exact millisecond you run torch.load(). Attackers don't need to break complex encryption. They just wrap a malicious shell script inside a pickle payload, upload it as a "fine-tuned sentiment analyzer," and wait for unsuspecting engineers to run it.

# What developers think they are doing
model = torch.load("cool-community-model.pt")

# What actually happens under the hood
# The pickle payload opens a reverse shell to an attacker server

Once that code runs, the attacker gains full user privileges on your machine or cloud container. If that container has access to production credentials, your entire infrastructure is compromised.

The Danger of Exposed OpenAI Keys and Hidden Scripts

The problem doesn't stop at arbitrary code execution. Researchers constantly scan open repositories for hardcoded API keys.

Engineers routinely test open-source models alongside proprietary APIs like OpenAI or Anthropic. During local testing, developers accidentally commit .env files, config files, or hardcoded API keys directly into public Hugging Face spaces or GitHub repos.

Automated bots crawl these platforms 24 hours a day. When an OpenAI key leaks, bots scrap it within seconds. They exhaust your API rate limits, run up massive bills, or use your corporate account to generate malicious spam or run jailbroken prompts.

When you combine malicious model weights with leaked credentials, you get a double hit. The attacker steals your credentials while using your local compute resources to scan your internal network.

Safetensors Is Not a Complete Shield

To fix the pickle execution risk, Hugging Face introduced the safetensors format. It stores raw tensor buffers without allowing arbitrary code execution.

That solves part of the problem. Safetensors prevents a model file from executing bash commands on startup. But it doesn't fix the human factor.

Many repositories don't just host weights; they host custom code snippets, custom_code=True flags in Transformers, and execution scripts meant to run pre-processing pipelines. If a developer uses AutoModel.from_pretrained("user/repo", trust_remote_code=True), they completely bypass the protection offered by safetensors. You just told your interpreter to download and run whatever Python files the owner put in that repository.

Trusting remote code from an unverified user on a public platform is basic security negligence, yet thousands of tutorials recommend doing it just to get code working quickly.

What Engineering Teams Should Do Right Now

Fixing this isn't complicated, but it requires changing lazy habits.

  • Stop using trust_remote_code=True in production pipelines unless you have manually audited every line of Python inside that repository.
  • Convert legacy .pt and .bin weights to .safetensors before loading them locally, or download only verified safetensors weights.
  • Scan repositories for secrets using automated tools like trufflehog or gitleaks before committing code.
  • Isolate model execution environments. Run untrusted model weights inside locked-down containers with restricted network access so a compromised model can't talk to your internal databases.
  • Rotate your API keys regularly and set strict hard spend limits on OpenAI and Cloud billing accounts.

Open-source AI relies entirely on trust. Right now, attackers are exploiting that trust faster than security teams can patch python libraries. Check your dependencies today before someone else does it for you.

LM

Lily Morris

With a passion for uncovering the truth, Lily Morris has spent years reporting on complex issues across business, technology, and global affairs.