On 31 May 2024, Hugging Face disclosed that it had detected unauthorized access to its Spaces platform, the hosted runtime where developers publish Gradio and Streamlit demos. The access related to Spaces secrets, and the company said it suspected a subset of those secrets could have been reached. It revoked a number of the tokens it found in those secrets, emailed the users concerned, and told everyone to refresh any key or token and move to fine-grained access tokens.
Hugging Face did not publish how the access happened or how many users were affected, so this is not a forensic account and should not be read as one. Two years on, the more useful question is why a leak of secrets from a demo platform mattered at all. For a team using Spaces as a sandbox, it was an afternoon of key rotation. For a team that had wired Spaces into internal pipelines, stored unscoped cloud and model-provider keys in its environment, and pulled model weights into production without pinning them, the same event was far more serious.
What Ends Up in a Space
Spaces exists to remove friction. Push a README.md and an app.py, paste your API keys into the settings tab, and a container builds and serves your model to the world. The risk lies in what accumulates behind that settings tab once a convenience platform becomes part of a supply chain.
A Space often needs to authenticate against private repositories, call external model APIs and read datasets from cloud storage. The kinds of credential that commonly end up in its secrets are:
Mainstream software engineering spent a decade learning not to put long-lived cloud credentials in shared CI runners without federation and tight scopes. In ML engineering, the rush to ship interactive demos brought the old habit back.
— Hugging Face, Space secrets leak disclosure, 31 May 2024
Why Write Access to a Model Hub Can Mean Code Execution
If an attacker steals a write token for a package registry, they can publish a malicious update and wait for someone to install it. On a model hub the path from stolen write token to code running inside a victim's infrastructure can be quieter, because a great deal of the ecosystem still loads weights in Python's pickle format.
A pickled PyTorch checkpoint is not a passive table of numbers. It is a program for a small stack-based virtual machine, and loading it can run code. Recent PyTorch releases default torch.load() to a restricted weights-only mode, which helps, but older versions, explicit opt-outs and other pickle-based formats remain common. If an attacker can overwrite a checkpoint in a repository you trust, every pipeline that loads it without safetensors and without pinning a commit is exposed.
— Trail of Bits, Exploiting ML models with pickle file attacks, June 2024
Put the two halves together and a plausible chain looks like this. A developer creates a public Space to show a prototype and gives it a broad HF_TOKEN. That token leaks. The attacker has no interest in the demo; they use the token to push a modified checkpoint, or a changed model code file that runs whenever a consumer passes trust_remote_code=True, to the organization's main model repository. That night an automated job pulls main from the hub into a private network. Nothing in the 2024 disclosure says this happened. The point is that nothing in a typical setup prevents it.
Four Habits That Widen the Blast Radius
Four habits turn an upstream leak into your incident:
Hardening the boundary between a public hub and your own compute does not mean giving up open weights. It means treating a model pull with the suspicion you already apply to an untrusted container image:
Why Hub-Side Scanning Is Not Your Boundary
Hugging Face runs malware scanning, pickle scanning and secret scanning on the hub, and offers fine-grained token permissions. Those are worth having and worth using. Relying on them as your main boundary runs into three limits:
What to Do This Week
If you use Spaces for demos or internal tools: audit every Space in your organization. Delete the ones nobody maintains. For the rest, take raw cloud and model-provider keys out of the secrets and call a small rate-limited proxy in your own infrastructure, or bind the keys to throwaway accounts with hard spending caps.
If you pull models into training or inference: stop using floating references in automated pipelines. Give every from_pretrained() call an explicit commit hash through revision= and pass use_safetensors=True. Better still, treat the hub the way you treat a public container registry: pull once into internal storage after scanning, and block production nodes from reaching the public hub.
If you own token hygiene: move to fine-grained tokens everywhere. No automated service should hold a broad user token. A token inside a container should have read access to the one repository it needs and write access to nothing.
Conclusion
Hugging Face disclosed promptly, revoked the tokens it knew were at risk, removed org tokens, brought in outside specialists and changed how Spaces secrets are stored. The platform is better for it. Praising or blaming the platform still misses the architectural point.
The AI ecosystem built much of its supply chain on a collaborative hub designed for fast experiments. If production secrets sit in public demo containers and unpinned, executable weights flow from the public internet into privileged clusters, an upstream leak does not stay upstream. Isolate your secrets, pin your hashes, and stop letting production execute whatever is at the tip of someone else's branch.