CVE-2025-6051: Hugging Face Transformers Library Regular Expression Denial of Service Vulnerability
Summary
CVE-2025-6051: Hugging Face Transformers library has Regular Expression Denial of Service. Affects transformers versions < 4.53.0. Fixed in 4.53.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 library for natural language processing tasks, including text generation, translation, and text-to-speech. It provides pre-trained models and tools for working with various languages and tasks. The library is known for its ease of use and integration with popular machine learning frameworks. However, it has been found to have a vulnerability that affects its number normalization functionality, which is critical for tasks that involve numeric data processing.
Vulnerability Detail
A Regular Expression Denial of Service (ReDoS) vulnerability exists in the Hugging Face Transformers library, specifically in the normalize_numbers() method of the EnglishNormalizer class. This vulnerability affects versions up to 4.52.4 and is addressed in version 4.53.0. The issue arises from the method's handling of numeric strings, which can be exploited by providing crafted input strings with long sequences of digits. This can lead to excessive CPU consumption, causing service disruptions, resource exhaustion, and potential API vulnerabilities in applications relying on this library.
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.53.0
This is the first release that contains the fix.
pip install --upgrade "transformers==4.53.0"
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
If you cannot immediately update the library, consider implementing input validation to limit the length of numeric strings processed by the normalize_numbers() method. This can help mitigate the risk of excessive CPU consumption. For example, you can restrict input to a maximum length of 10 digits before passing it to the method.
Conclusion
The Hugging Face Transformers library has a ReDoS vulnerability that affects its number normalization functionality. It is crucial for users of the library to update to version 4.53.0 or later to mitigate this risk. Additionally, implementing input validation can serve as a temporary workaround until the library is updated.
See every vulnerability recorded for transformers →
FAQ
A ReDoS vulnerability occurs when an application processes user input with regular expressions in a way that can lead to excessive resource consumption, often causing the application to slow down or crash.
Versions of the Hugging Face Transformers library up to 4.52.4 are affected by this vulnerability. The issue is fixed in version 4.53.0.
You can use Vulert, a tool that monitors and alerts for open-source vulnerabilities in your software. By uploading your Pipfile.lock to Vulert, you can check for vulnerabilities without needing to access the code directly.
The vulnerability can lead to excessive CPU usage, service disruptions, and resource exhaustion, which can affect the performance and availability of applications using the library.
Yes, you can implement input validation to limit the length of numeric strings processed by the normalize_numbers() method, which can help reduce the risk of CPU exhaustion.
References
Related vulnerabilities
Recent vulnerabilities recorded for transformers.