CVE-2025-3262: Transformers vulnerable to ReDoS attack through its SETTING_RE variable
Hugging Face Transformers 4.49.0 up to 4.50.x has a regular expression denial of service in the SETTING_RE pattern in transformers/commands/chat.py. A crafted almost-matching string makes the regex backtrack heavily and burn CPU. Only the chat command is involved. Upgrade to transformers 4.51.0.
Published Jul 7, 2025 · Updated Aug 4, 2025 · Analysis Nov 1, 2026
What an attacker can do
The transformers chat command accepts set key=value commands, including several pairs separated by semicolons. The SETTING_RE pattern, which began with ^set\s+[A-Za-z\s_]+=, used repeated groups and non-optimized quantifiers. The advisory says input that almost matches causes exponential backtracking, which degrades performance and can lead to denial of service.
The attacker must get a crafted string into that chat command's input. That fits a narrow case: a service or terminal session that exposes the chat command to untrusted users. Most applications that import the Transformers library never run this code, so exposure is small. The CVSS vector scores network access with no privileges and low availability impact only. There is no data exposure or code execution.
The effect is one process stuck on CPU. A shared inference host running the chat command for several users could see slow responses for everyone until the process is killed.
Who is affected
The package data lists transformers from 4.49.0 up to but not including 4.51.0. The advisory names 4.49.0 as the version where the issue was found. You are exposed only if you run the transformers chat command, or code that wraps it, on input from people you do not trust.
pip show transformersCheck images and virtual environments separately, as they often pin different versions.
transformers
- Ecosystem
- PyPI
- Affected
- >= 4.49.0, < 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 fix commit, 126abe3, removes SETTING_RE and adds a static method, is_valid_setting_command, in chat.py. It requires input to start with set and contain an equals sign, splits on semicolons, needs exactly one equals sign per assignment, rejects empty keys and values, and checks keys and values against allowed character sets. No regex runs on the input. The sources give no other workaround. If you cannot upgrade, do not expose the chat command to untrusted input.
How to tell if you were hit
Look for a transformers chat process pinned at high CPU with input that begins with set and contains long runs of letters, spaces or underscores that never reach a valid equals sign. A stack dump of a stuck process shows frames in the re module called from chat.py. Check version pins in every environment that ships transformers, and whether anything exposes the chat command beyond your own terminal.
Original advisory
From the GitHub Advisory Database (CC BY 4.0).
A Regular Expression Denial of Service (ReDoS) vulnerability was discovered in the huggingface/transformers repository, specifically in version 4.49.0. The vulnerability is due to inefficient regular expression complexity in the SETTING_RE variable within the transformers/commands/chat.py file. The regex contains repetition groups and non-optimized quantifiers, leading to exponential backtracking when processing 'almost matching' payloads. This can degrade application performance and potentially result in a denial-of-service (DoS) when handling specially crafted input strings. The issue is fixed in version 4.51.0.
Questions
- Does CVE-2025-3262 affect every use of Transformers?
No. The flaw is in the regex used by the chat command in transformers/commands/chat.py. Code that only loads models or runs pipelines does not use that pattern.
- Which version fixes it?
transformers 4.51.0. The affected range in the package data is 4.49.0 up to 4.51.0.
- What is the worst outcome?
Denial of service. The CVSS vector shows low availability impact and no confidentiality or integrity impact. A crafted input ties up CPU in the affected process.
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-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
