How to fix: HuggingFace write token in source
hf_* tokens grant model / dataset upload access.
Why it matters
An exposed HuggingFace write token lets an attacker upload malicious model weights or datasets under your account identity, a supply-chain attack that affects anyone who downloads and runs those models, potentially including your own users.
hf_* tokens grant model / dataset upload access.
How to fix it
- 1Revoke the token at huggingface.co/settings/tokens
- 2Create a read-only token for inference use in client/server code
- 3Use a write token only in CI pipelines via secrets manager
Code examples
Use read-only token for inference
from huggingface_hub import InferenceClient
import os
# Use a read-only token for inference: never a write token
client = InferenceClient(
model="mistralai/Mistral-7B-Instruct-v0.1",
token=os.environ['HF_READ_TOKEN'], # read-only token from env
)References
Detected automatically by VulnRadar. The check id is secret-huggingface-write-token, stable across every scan so you can filter or diff on it.
More secrets checks
Questions
- How severe is HuggingFace write token in source?
- VulnRadar rates this high severity in the secrets category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
- Does VulnRadar check for this automatically?
- Yes. It runs as part of every scan under the check id secret-huggingface-write-token, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does HuggingFace write token in source map to?
- It maps to CWE-798. In the OWASP Top 10 it falls under A07:2021.
Missing a check?
The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.