NewApp Monitoring is liveSign up free
AgentbeamBeta
AI agent vulnerability · Transformers

CVE-2025-2099: Hugging Face Transformers Regular Expression Denial of Service

mediumCVSS 3.0 5.3GHSA-qq3j-4f4f-9583

Hugging Face Transformers before 4.50.0 has a ReDoS flaw in `preprocess_string()` in `transformers.testing_utils`. A regex with nested quantifiers backtracks catastrophically on input with many newlines and burns CPU. Fixed in 4.50.0.

Published May 19, 2025 · Updated Sep 25, 2025 · Analysis Nov 1, 2026

What an attacker can do

preprocess_string() lives in the transformers.testing_utils module, a helper used for testing docstrings. It uses a regex to process code blocks in docstrings. The pattern has nested quantifiers, so a string with many newline characters makes the matcher backtrack for a very long time.

To exploit it, an attacker must be able to feed such a string into preprocess_string() or into code that calls it. That is a narrow path. Most production inference code never imports testing_utils, so the realistic exposure is test and documentation tooling, CI jobs, or a custom service that passes outside text to this function. The CVSS 3.0 vector rates it network, no privileges, low availability impact and nothing else. The result is high CPU use and a degraded process, not code execution or data loss.

Who is affected

Affected: transformers before 4.50.0. Check the version:

pip show transformers

The vulnerable code is only reachable if something in your stack calls preprocess_string() from transformers.testing_utils, directly or indirectly. Search your code for that import.

transformers

Ecosystem
PyPI
Affected
< 4.50.0
Fixed in
4.50.0
Check
pip show transformers

How to fix it

Upgrade to 4.50.0, which rewrites the regex to avoid the inefficient pattern:

pip install --upgrade transformers==4.50.0

The change is in pull request 36648. The advisory lists no workaround. If you cannot upgrade, do not pass untrusted text to preprocess_string().

How to tell if you were hit

Look for Python processes stuck at 100% CPU inside re matching, with a stack trace that points at transformers/testing_utils.py. A py-spy dump of a hung worker shows this quickly. Check inputs for very long runs of newline characters. The advisory gives no log signature.

Original advisory

From the GitHub Advisory Database (CC BY 4.0).

A Regular Expression Denial of Service (ReDoS) exists in the preprocess_string() function of the transformers.testing_utils module. In versions before 4.50.0, the regex used to process code blocks in docstrings contains nested quantifiers that can trigger catastrophic backtracking when given inputs with many newline characters. An attacker who can supply such input to preprocess_string() (or code paths that call it) can force excessive CPU usage and degrade availability.

Fix: released in 4.50.0, which rewrites the regex to avoid the inefficient pattern. ([GitHub][1])

  • Affected: < 4.50.0
  • Patched: 4.50.0

Credited to cai0duque.

Questions

Does CVE-2025-2099 affect normal model inference?

Probably not. The flaw is in transformers.testing_utils, which production inference code rarely imports. You are exposed only if your code feeds outside input to preprocess_string().

Which Transformers version fixes it?

4.50.0. All earlier versions are listed as affected.

How severe is it?

Medium. The CVSS 3.0 score is 5.3, with low availability impact and none for confidentiality or integrity. Its EPSS score is 0.0061, and it is not in the CISA KEV catalog.

References

How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. The analysis is written by an AI model from the sources listed above and checked by automated rules before it is published. Check versions against the vendor's advisory before you act. Methodology

More Transformers vulnerabilities

All Transformers entries