Hugging Face Transformers downloads custom generation code before trust consent
High7.8CVE-2026-80047 · Published Sep 1, 2026 · updated Oct 1, 2026
A vulnerability in Hugging Face Transformers (versions 4.49.0, <= 5.8.1) allows remote Python files to be written to local disk without user consent when using GenerativePreTrainedModel.load_custom_generate(). The function fetches and caches a remote module file before performing the required trust_remote_code consent check, inverting the security model enforced by other code-loading paths (such as AutoConfig, AutoModel, and AutoTokenizer). As a result, attacker‑controlled Python code from custom_generate/generate.py is copied into the user’s ~/.cache/huggingface/modules directory even if the user declines the trust prompt. Although execution is correctly gated, the file write is not reversible and can persist across sessions. This can lead to persistent, unauthorized files on disk and stale cache collisions where cached attacker code may later be executed during trusted model loads. The issue stems from an unconditional file write in dynamic_module_utils.py prior to any trust verification.
Affected versions
| Package | Affected | Fixed in |
|---|---|---|
| transformers PyPI | >= 4.49.0, <= 5.8.1 | No fix yet |
Details and references
- CVSS 3.1
- CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
- Severity from
- GitHub (reviewed advisory)
- Weakness
- CWE-273
- Also known as
- CVE-2026-80047, PYSEC-2026-4174
More Transformers advisories
All Transformers| Date | Advisory | Severity | Fixed in |
|---|---|---|---|
| Aug 2 | Transformers save_pretrained path traversal allows arbitrary file writes through chat template names | High7.1 | 5.10.0 |
| Jun 3 | Transformers: code execution | High8.0 | 5.5.0 |
| May 26 | HuggingFace transformers vulnerable to remote code execution | High7.8 | 5.3.0 |
| Apr 7 | HuggingFace Transformers allows for arbitrary code execution in the `Trainer` class | Medium6.5 | 5.0.0rc3 |
| Dec 232025 | Transformers: code injection | High7.8 | No fix yet |
| Dec 232025 | Transformers: unsafe deserialization | High7.8 | No fix yet |