PyPI: transformers

CVE-2025-3262

Safety vulnerability ID: SFTY-20250707-48060

Safety legacy ID: pyup.io-77990

Affected versions of the Hugging Face Transformers package are vulnerable to Regular Expression Denial of Service (ReDoS) due to inefficient regex patterns in multiple components. The vulnerable regular expressions in `serve.py`, `user.py`, and `utils.py` fail to handle catastrophic backtracking efficiently when processing specially crafted input strings, allowing exponential time complexity. A remote attacker can exploit this vulnerability by providing malicious input strings that cause excessive CPU consumption during regex matching operations, resulting in a denial of service. The vulnerability was fixed by refactoring the problematic regex patterns to use more efficient alternatives. The fix replaces complex regex operations with simpler string manipulation methods, implements input validation before regex processing, and rewrites patterns to avoid nested quantifiers and catastrophic backtracking. Specifically, the commit modifies regex handling in the model serving components and user input processing functions to prevent ReDoS attacks.

Created at: Nov 5, 2025Updated at: Nov 5, 2025

Overview

Transformers vulnerable to ReDoS attack through its SETTING_RE variable

Advisory

Affected versions of the Hugging Face Transformers package are vulnerable to Regular Expression Denial of Service (ReDoS) due to inefficient regex patterns in multiple components. The vulnerable regular expressions in `serve.py`, `user.py`, and `utils.py` fail to handle catastrophic backtracking efficiently when processing specially crafted input strings, allowing exponential time complexity. A remote attacker can exploit this vulnerability by providing malicious input strings that cause excessive CPU consumption during regex matching operations, resulting in a denial of service. The vulnerability was fixed by refactoring the problematic regex patterns to use more efficient alternatives. The fix replaces complex regex operations with simpler string manipulation methods, implements input validation before regex processing, and rewrites patterns to avoid nested quantifiers and catastrophic backtracking. Specifically, the commit modifies regex handling in the model serving components and user input processing functions to prevent ReDoS attacks.

Affected Package

Affecting transformers package, versions
>=4.49.0,<4.51.0

Also affects

---

How to Fix

Upgrade
transformers
to
4.51.0
or higher.

Mitigation and Workarounds

---

Vulnerable Functions

Functions linked to known vulnerabilities.

Vulnerable function data is available for Enterprise customers

Book a call with us to see Safety in action.

Safety

Verified by Safety

Our Cybersecurity Intelligence Team reviewed this vulnerability. We combine public data with our own research to find issues not yet reported to public sources.

Learn more