CVE-2025-3264: Transformers vulnerable to ReDoS attack through its get_imports() function
The get_imports() function in transformers dynamic_module_utils.py strips try/except blocks from Python source with the regex \s*try\s*:.*?except.*?:, which backtracks catastrophically on crafted code. Loading a malicious remote model's code can hang the loader and exhaust CPU. Versions below 4.51.0 are listed as vulnerable. Upgrade to 4.51.0.
Published Jul 7, 2025 · Updated Jul 8, 2025 · Analysis Nov 1, 2026
What an attacker can do
dynamic_module_utils.py handles models that ship their own Python code, loaded with trust_remote_code. get_imports() reads that source to work out which packages it imports, and first removes try/except blocks using the regex above. The advisory says a crafted file triggers catastrophic backtracking and excessive CPU use.
The attacker is the author of a model repository or a file that your code loads. They publish a repo with a Python file built to stall the regex. Anyone who loads it, in a notebook, a CI job or a model-serving service, ties up a CPU core. The advisory lists remote code loading disruption, resource exhaustion in model serving, supply chain attack vectors and development pipeline disruption. The CVSS vector shows network access, no privileges, no user interaction, and low availability impact only.
This flaw does not run the attacker's code. The hang happens while the file is scanned. Still, the same repository would be dangerous to load for other reasons, so it only adds to the case for pinning and reviewing remote code.
Who is affected
The package data and the advisory list transformers below 4.51.0. The description names 4.49.0, so the lower bound is unclear. Treat all versions below 4.51.0 as in scope. The risk applies to workflows that load models with custom code from repositories you do not control.
pip show transformersSearch your code for trust_remote_code=True.
transformers
- Ecosystem
- PyPI
- Affected
- < 4.51.0
- Fixed in
- 4.51.0
- Check
pip show transformers
How to fix it
Upgrade to transformers 4.51.0.
pip install --upgrade "transformers>=4.51.0"The advisory points to upstream commits 0720e20 and 126abe3 but does not describe the change to get_imports(). The sources give no workaround. Until you upgrade, load only trusted models, pin models to a reviewed revision, and set timeouts and CPU limits on jobs and workers that load remote models.
How to tell if you were hit
Look for model-loading jobs or workers stuck at high CPU while resolving a model with custom code, especially right after a new or changed repository was pulled. A stack dump of the stuck process shows frames in the re module called from get_imports in dynamic_module_utils.py. List the repositories you load with trust_remote_code, and check which of them changed recently. Check version pins for transformers below 4.51.0 in every environment.
Original advisory
From the GitHub Advisory Database (CC BY 4.0).
A Regular Expression Denial of Service (ReDoS) vulnerability was discovered in the Hugging Face Transformers library, specifically in the get_imports() function within dynamic_module_utils.py. This vulnerability affects versions 4.49.0 and is fixed in version 4.51.0. The issue arises from a regular expression pattern \s*try\s*:.*?except.*?: used to filter out try/except blocks from Python code, which can be exploited to cause excessive CPU consumption through crafted input strings due to catastrophic backtracking. This vulnerability can lead to remote code loading disruption, resource exhaustion in model serving, supply chain attack vectors, and development pipeline disruption.
Questions
- Does CVE-2025-3264 run attacker code?
No. It is a denial of service. The regex used to strip try/except blocks from a model's Python file backtracks and uses CPU. The CVSS vector shows low availability impact and nothing else.
- Who is exposed?
Workflows that load models with custom Python code, where the repository author is not trusted. The advisory lists model serving and development pipelines as affected.
- Which version fixes it?
transformers 4.51.0. Versions below it are listed as vulnerable, and the description names 4.49.0.
References
Read for this analysis:
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-80047
Hugging Face Transformers downloads custom generation code before trust consent
high7.8No fixSep 1, 2026CVE-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, 2025
