← cd ../blog
cat blog/hugging-face-spaces-shared-hub-fallacy.md — less — 80x24
Article

The Shared-Hub Fallacy:
What the 2024 Hugging Face Spaces Leak Still Teaches

--author perrmit --date 2026-05-31 --tags mlsecops, supply-chain, hugging-face, secrets-management, pickle-rce
Two years ago, Hugging Face disclosed unauthorized access to secrets stored in its Spaces platform and revoked the tokens it found there. It never said how many users were affected. The lesson did not need a number: a demo platform is not a vault, and model weights on a public hub are code, not inert data.

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.

THESIS: The incident is best understood as the meeting of two habits in AI engineering: handing high-privilege third-party secrets to a multi-tenant demo runtime, and treating serialized model weights on a public hub as inert data when they can be executable code.

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:

[SECRET A] broad_hf_tokens     — Read/write HF_TOKEN values bound to a whole user account or organization, not a single repository. One leaked token can mean write access to every model and dataset its owner controls.
[SECRET B] model_provider_keys — Production keys for commercial model APIs, added so a public demo can proxy calls. A leaked key can be spent by anyone who holds it.
[SECRET C] cloud_credentials   — Long-lived cloud access keys and service-account files used to read training data from object storage when the container starts.
[SECRET D] vector_db_keys      — Admin keys and connection strings for vector databases holding customer embeddings and internal documents.
[SECRET E] ci_tokens           — Personal access tokens and webhook secrets used by pipelines that sync code between a private Git host and the hub.

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.

WHAT CHANGED: In the same disclosure, Hugging Face said it had removed org tokens altogether, implemented a key management service (KMS) for Spaces secrets, improved its ability to identify leaked tokens and invalidate them proactively, and was working with outside forensic specialists. It also said it planned to deprecate classic read and write tokens once fine-grained tokens reached feature parity.
— 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.

RESEARCH: In June 2024, Trail of Bits described Sleepy Pickle: a technique in which a malicious pickle modifies the model itself as it is loaded, so that it can insert backdoors, steer outputs or leak user data. The payload does not need to drop an obvious file on disk or open a shell, which makes it harder to spot than a conventional pickle exploit.
— 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:

[FAIL] one_token_everywhere — One coarse write token reused on laptops, in CI and in hosted Spaces. If the platform revokes it after a leak, as Hugging Face did in 2024, everything that shares it stops at once, and until then everything that shares it is exposed.
[FAIL] unpinned_refs        — Calling from_pretrained("org/model-name") with no revision. That pulls the tip of main on every cold start, so a compromised upstream repository reaches production at the next scale-up.
[FAIL] blind_remote_code    — Treating trust_remote_code=True as boilerplate. Some architectures ship custom Python alongside their weights; the flag tells the library to download and run it.
[FAIL] static_cloud_keys    — Putting static cloud credentials into a third-party container platform when you could broker short-lived tokens or proxy calls through a gateway you control.

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:

step 1 prefer safetensors → set use_safetensors=True; refuse legacy pickle files step 2 pin an immutable commit → revision="<full commit hash>" defeats branch hijacking step 3 no trust_remote_code in prod → vendor custom model code into your own reviewed tree step 4 mirror to a private registry → scan in staging; keep production off the public hub step 5 scope tokens to one repo → fine-grained, read-only; no write tokens in Spaces
CAVEAT: safetensors removes code execution at load time, which closes the pickle route. It says nothing about what the weights compute. A file uploaded with a stolen write token can still carry a fine-tuned backdoor. Format safety is not provenance; pinning commits and mirroring artifacts address both.

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:

[WATCH] scanners_are_blocklists     — A static pickle scanner looks for known dangerous imports. Researchers have repeatedly published ways around such scanners, in the same way that shell filters are bypassed.
[WATCH] trust_moves_with_the_repo   — If a legitimate maintainer's token is stolen, the malicious commit lands in a repository you reviewed months ago. Unless you pin the exact commit, your earlier trust transfers to the new content.
[WATCH] someone_else_holds_the_keys — A secret stored in a third-party runtime is as safe as that platform's control plane. Envelope encryption raises the cost of a database dump; it does not protect a secret that is live in a running container.

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.

STATUS: Org tokens are gone, Spaces secrets sit behind a KMS, and fine-grained tokens are the default for new tokens. The downstream risks are unchanged wherever pipelines still use unpinned from_pretrained() calls, trust_remote_code=True and over-privileged tokens.