Skip to content
TransformersGHSA-x9r9-c232-4q39

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.

GitHub advisory

Affected versions

PackageAffectedFixed in
transformers
PyPI
>= 4.49.0, <= 5.8.1No fix yet
Details and references

More Transformers advisories

All Transformers
Advisory
Transformers save_pretrained path traversal allows arbitrary file writes through chat template names
High7.1Aug 2
Transformers: code execution
High8.0Jun 3
HuggingFace transformers vulnerable to remote code execution
High7.8May 26
HuggingFace Transformers allows for arbitrary code execution in the `Trainer` class
Medium6.5Apr 7
Transformers: code injection
High7.8Dec 23, 2025
Transformers: unsafe deserialization
High7.8Dec 23, 2025

Critical advisories by email

Wednesdays: the week’s critical and high advisories in the AI and data stack, with the fixed versions. Only in weeks that have some.

Double opt-in. Unsubscribe any time.