CVE-2025-5197: Hugging Face Transformers Regular Expression Denial of Service (ReDoS) Vulnerability
Summary
CVE-2025-5197: Hugging Face Transformers Regular Expression Denial of Service (ReDoS) vulnerability. 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 that facilitates the use of state-of-the-art natural language processing models. It allows users to easily convert models between different frameworks, such as TensorFlow and PyTorch. The library is known for its flexibility and extensive model support, making it a popular choice among developers and researchers in the AI community. However, it has been found to contain a vulnerability that can lead to Denial of Service (DoS) attacks through regular expressions.
Vulnerability Detail
A Regular Expression Denial of Service (ReDoS) vulnerability exists in the Hugging Face Transformers library, specifically in the convert_tf_weight_name_to_pt_weight_name() function. This function uses a regex pattern that can be exploited to cause excessive CPU consumption through crafted input strings due to catastrophic backtracking. The vulnerability affects versions up to 4.51.3 and can lead to service disruption, resource exhaustion, and potential API service vulnerabilities, impacting model conversion processes between TensorFlow and PyTorch formats.
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
As a temporary workaround, avoid using the convert_tf_weight_name_to_pt_weight_name() function with untrusted input. Validate and sanitize any input strings before processing them to mitigate the risk of triggering the vulnerability.
Conclusion
The Hugging Face Transformers library has a vulnerability that can lead to Denial of Service attacks through regular expressions. It is crucial for users to update to version 4.53.0 or later to mitigate this risk. Additionally, employing workarounds and monitoring tools like Vulert can help safeguard applications from potential threats.
See every vulnerability recorded for transformers →
FAQ
The CVSS score of this vulnerability is 5.3, indicating a moderate severity level.
Versions up to 4.51.3 of the Hugging Face Transformers library are affected by this vulnerability.
You can use the Vulert playground at Vulert Scanner to check if your application is affected by this vulnerability without requiring any signup.
The potential consequences include service disruption, resource exhaustion, and vulnerabilities in API services, which can impact model conversion processes.
Yes, Vulert can monitor and alert you in real-time for open-source vulnerabilities in your software using just the Pipfile.lock.
References
Related vulnerabilities
Recent vulnerabilities recorded for transformers.