Skip to content
RCE Write-up Advanced

Hijacking Safetensors Conversion On Hugging Face

The Hugging Face Safetensors conversion service loaded PyTorch models with torch.load(), allowing arbitrary code execution. An attacker could exploit this to steal the SFconvertbot token, impersonate the bot to send malicious pull requests to any repository, and persist code to hijack models during conversion.

Eoin Wickens Follow

Published on hiddenlayer.com

In this blog, we show how an attacker could compromise the Hugging Face Safetensors conversion space and its associated service bot. These comprise a popular service on the site dedicated to converting insecure machine learning models within their ecosystem into safer versions.

Eoin Wickens (@enwckns), Kasimir Schulz (@Abraxus7331), on hiddenlayer.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The service used torch.load() to load untrusted PyTorch models, which can execute arbitrary code, and the bot's token was accessible in the same environment.

Impact

An attacker could impersonate the official bot to send malicious pull requests to any repository, potentially implanting backdoors or degrading models, and could persist code to hijack any model submitted for conversion, affecting many users.

What the attacker needed

A Hugging Face account; ability to create a repository with a PyTorch model; the conversion service is running

The fix

The service should not use torch.load() on untrusted models; instead, it should use safe loading methods or scan models for malicious content before loading.

How it was found

  1. Create a malicious PyTorch model with a payload that executes code.
  2. Submit the model to the conversion service via the web interface.
  3. The service loads the model with torch.load(), executing the payload.
  4. Use the payload to bypass the file size check by overwriting the check_file_size function.
  5. Exfiltrate the SFconvertbot token via a webhook.
  6. Use the token to send pull requests to any repository and persist code to hijack future conversions.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

The conversion service used a function that can run code hidden inside model files. An attacker could upload a malicious model to run their own code on the service, steal the bot's credentials, and then use the bot to send harmful changes to other people's projects.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More from Hugging Face

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.