CVE-2026-80047: Hugging Face Transformers downloads custom generation code before trust consent
In Hugging Face Transformers 4.49.0 through 5.8.1, `GenerativePreTrainedModel.load_custom_generate()` downloads a model repo's `custom_generate/generate.py` into the local module cache before it asks for `trust_remote_code` consent. The file stays on disk even if you decline. CERT/CC reports no fixed release.
Published Sep 1, 2026 · Updated Sep 30, 2026 · Analysis Oct 24, 2026
What an attacker can do
Other code-loading paths, such as AutoConfig, AutoModel and AutoTokenizer, check consent first. load_custom_generate() fetches and caches the remote module in dynamic_module_utils.py before the check. Attacker-controlled Python from custom_generate/generate.py is copied into ~/.cache/huggingface/modules even when the user says no.
Execution itself is still gated. The harm is the file left behind. It persists across sessions and cannot be undone by declining. If a later trusted model load uses the same cache path, a stale cache collision can cause the attacker's cached code to run. That is how persistent files become code execution.
The attacker needs the victim to call load_custom_generate() against a model repo the attacker controls. They publish such a repo and get it loaded, for example through a tutorial, a shared notebook, or an agent that pulls models. The CVSS vector assumes local access with low privileges, and the advisory describes unauthorized files on disk and conditional execution, not direct remote execution.
Who is affected
The transformers pip package from 4.49.0 through 5.8.1. Code that never calls load_custom_generate() does not hit this path.
pip show transformersThen look in the cache for unexpected modules:
ls ~/.cache/huggingface/modulestransformers
- Ecosystem
- PyPI
- Affected
- >= 4.49.0, <= 5.8.1
- Fixed in
- No patched version yet
- Check
pip show transformers
How to fix it
No patched version is listed. CERT/CC states that no vendor fix or statement existed when it published its note. A fix is proposed in pull request 48620 (commit cbc1651), but the sources do not name a release containing it, so check the release notes before relying on it.
Until then, use the workarounds from CERT/CC:
- Do not call
load_custom_generate()with untrusted model repositories. - Inspect and clear
~/.cache/huggingface/modulesregularly to remove unexpected files.
How to tell if you were hit
List ~/.cache/huggingface/modules and look for directories or generate.py files you did not expect, especially ones that match model repos you declined to trust. Compare file times against your load_custom_generate() calls. In shared environments, check each user's cache and any cache directory set through Hugging Face environment variables.
Original advisory
From the GitHub Advisory Database (CC BY 4.0).
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.
Questions
- Does declining trust_remote_code protect me?
Not fully. The file is written to disk before the prompt, so it remains in the cache after you decline, although it is not executed at that moment.
- Is there a patched Transformers version?
None is listed. CERT/CC says no fix existed at the time of its note. Pull request 48620 holds a proposed fix.
- How could the cached file run later?
Through a stale cache collision: a trusted model load that resolves to the same cached module could execute the attacker's code.
- Which versions are affected?
4.49.0 through 5.8.1, and only code that calls
load_custom_generate().
References
How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. The analysis is written by an AI model from the sources listed above and checked by automated rules before it is published. Check versions against the vendor's advisory before you act. Methodology
More Transformers vulnerabilities
All Transformers entriesCVE-2026-9856
Transformers save_pretrained path traversal allows arbitrary file writes through chat template names
high7.1Aug 2, 2026CVE-2026-5241
huggingface/transformers: Arbitrary Code Execution During Model Initialization in the LightGlue Model Loading Path
high8.0Jun 3, 2026CVE-2026-4372
HuggingFace transformers vulnerable to remote code execution
high7.8May 26, 2026CVE-2026-1839
HuggingFace Transformers allows for arbitrary code execution in the `Trainer` class
medium6.5Apr 7, 2026CVE-2025-6921
Hugging Face Transformers vulnerable to Regular Expression Denial of Service (ReDoS) in the AdamWeightDecay optimizer
medium5.3Sep 23, 2025CVE-2025-6051
Hugging Face Transformers library has Regular Expression Denial of Service
medium5.3Sep 14, 2025
