CVE-2025-3264: Hugging Face Transformers Vulnerable to ReDoS Attack via get_imports() Function
Summary
CVE-2025-3264: Transformers vulnerable to ReDoS attack through its get_imports() function. Affects transformers versions < 4.51.0. Fixed in 4.51.0. How to fix ↓
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
The Hugging Face Transformers library is a widely-used open-source framework designed for natural language processing tasks. It provides pre-trained models and tools for building and deploying machine learning applications. However, a vulnerability has been identified in version 4.49.0 that exposes the library to Regular Expression Denial of Service (ReDoS) attacks, which can severely impact performance and availability.
Vulnerability Detail
A Regular Expression Denial of Service (ReDoS) vulnerability exists in the Hugging Face Transformers library, specifically within the get_imports() function in dynamic_module_utils.py. The vulnerability is caused by a regex pattern '\stry\s:.?except.?:' that is used to filter try/except blocks from Python code. This pattern can be exploited through crafted input strings, leading to catastrophic backtracking and excessive CPU consumption. The potential consequences include disruption of remote code loading, resource exhaustion during model serving, and possible supply chain attack vectors.
How To Fix
Latest published version: 5.20.2 as of 22 Oct 2026
pip install --upgrade "transformers==5.20.2"
Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.
If you need the minimum change
4.51.0
This is the first release that contains the fix.
pip install --upgrade "transformers==4.51.0"
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
If you cannot immediately upgrade the library, consider implementing input validation to restrict the types of strings that can be processed by the get_imports() function. This may help mitigate the risk of triggering the ReDoS vulnerability.
Conclusion
The Hugging Face Transformers library has a vulnerability that exposes it to ReDoS attacks through its get_imports() function. Users are advised to upgrade to version 4.51.0 or later to mitigate this risk. Implementing input validation can also serve as a temporary workaround. For ongoing monitoring, consider using Vulert to stay informed about vulnerabilities in your software.
See every vulnerability recorded for transformers →
FAQ
A ReDoS (Regular Expression Denial of Service) attack exploits the performance issues of regular expressions, causing excessive CPU usage and potentially crashing the application.
Versions prior to 4.51.0 are affected by this vulnerability. It is recommended to upgrade to version 4.51.0 or later.
The vulnerability can lead to remote code loading disruption, resource exhaustion in model serving, and possible supply chain attacks.
You can use Vulert, which monitors and alerts for open-source vulnerabilities in real-time. You can check your application against this vulnerability using the Vulert playground without any signup.
The CVSS score for this vulnerability is 5.3, indicating a moderate severity level.
References
Related vulnerabilities
Recent vulnerabilities recorded for transformers.