Hugging Face Transformers Regular Expression Denial-of-Service Vulnerability

Vulnerability

A Regular Expression Denial-of-Service (ReDoS) vulnerability exists in the Hugging Face Transformers library, specifically in the 'get_imports()' function within 'dynamic_module_utils.py'. This issue affects version 4.49.0 and can be exploited by using crafted input strings that cause excessive CPU consumption through catastrophic backtracking, disrupting remote code loading, exhausting resources in model serving, and potentially leading to supply chain attack vectors.

Impact

Exploitation of this vulnerability causes excessive CPU consumption, disrupting model serving and remote code loading, and potentially leading to supply chain attacks.

Reproduction

The vulnerability can be reproduced by using a version of the Hugging Face Transformers library prior to 4.51.0. The 'get_imports()' function in 'dynamic_module_utils.py' can be called with input that is crafted to exploit the regular expression pattern used to filter try/except blocks in Python code. This crafted input should be designed to cause catastrophic backtracking in the regular expression, leading to excessive CPU usage.

Remediation

Users can upgrade to Hugging Face Transformers version 4.51.0 or later to address this vulnerability.

Added: Jul 7, 2025, 10:40 AM
Updated: Jul 7, 2025, 10:40 AM

Vulnerability Rating

Custom Algorithm
spread
6.6
impact
2.5
exploitability
5.7
remediation
7.7
relevance
0.2
threat
4.8
urgency
2.9
incentive
1.7

Our algorithm analyzes dozens of metrics to generate these 8 key vulnerability categories, which are then combined to calculate the overall risk score.