AgentbeamBeta
AI agent vulnerability · Transformers

CVE-2025-6921: Hugging Face Transformers vulnerable to Regular Expression Denial of Service (ReDoS) in the AdamWeightDecay optimizer

mediumCVSS 3.0 5.3GHSA-4w7r-h757-3r74

Hugging Face Transformers before 4.53.0 passes the patterns in the AdamWeightDecay optimizer's include_in_weight_decay and exclude_from_weight_decay lists to re.search. A pattern that backtracks catastrophically pins a CPU core at 100% and hangs the training task. This is a denial of service. Fixed in 4.53.0.

Published Sep 23, 2025 · Analysis Nov 9, 2026

What an attacker can do

In the TensorFlow optimizer code (optimization_tf.py), the method _do_use_weight_decay loops over the include and exclude lists and calls re.search(r, param_name) for each entry. The entries are treated as regular expressions. A crafted expression, such as a nested quantifier, makes the regex engine backtrack for a very long time on a parameter name, so the process uses a full CPU and the training job stops making progress.

The attacker must control the patterns in those lists. That is not a typical remote input. It becomes relevant where users or other systems can submit training configurations, for example a hosted fine-tuning service, a shared notebook platform or a pipeline that builds optimizer settings from a request. There, one bad configuration can tie up a worker and make the service unresponsive. There is no impact on confidentiality or integrity, and the advisory scores availability only (low). Teams that write the lists themselves in their own code are not exposed in practice.

Who is affected

The pip package transformers before 4.53.0. Only code that uses the TensorFlow AdamWeightDecay optimizer with weight-decay include or exclude lists taken from untrusted input can be hit. Check the installed version:

pip show transformers

Then search your code and configuration for AdamWeightDecay, include_in_weight_decay and exclude_from_weight_decay, and see where the list values come from.

transformers

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

How to fix it

Upgrade to 4.53.0:

pip install --upgrade "transformers>=4.53.0"

The fix is in commit d37f7517972f67e3f2194c000ed0f87f064e5099, "Two ReDOS fixes". In _do_use_weight_decay, the re.search calls become plain substring checks (r in param_name), and the re import is removed. The same commit also removes a regex from the Marian tokenizer. A side effect is that the lists are now treated as plain substrings and no longer as regular expressions, so check any configuration that used regex syntax. The advisory lists no workaround. If you cannot upgrade, validate or fix the pattern lists yourself and never take them from untrusted input.

How to tell if you were hit

The sign is a training or fine-tuning process that sits at 100% of one CPU core without advancing, with a stack that shows re.search inside _do_use_weight_decay. Check job logs for runs that never finish their first steps. Review submitted configurations for include or exclude patterns with nested quantifiers, such as (a+)+ or long repeated groups.

Original advisory

From the GitHub Advisory Database (CC BY 4.0).

The huggingface/transformers library, versions prior to 4.53.0, is vulnerable to Regular Expression Denial of Service (ReDoS) in the AdamWeightDecay optimizer. The vulnerability arises from the _do_use_weight_decay method, which processes user-controlled regular expressions in the include_in_weight_decay and exclude_from_weight_decay lists. Malicious regular expressions can cause catastrophic backtracking during the re.search call, leading to 100% CPU utilization and a denial of service. This issue can be exploited by attackers who can control the patterns in these lists, potentially causing the machine learning task to hang and rendering services unresponsive.

Questions

Is every transformers user affected by CVE-2025-6921?

No. The flaw is in the TensorFlow AdamWeightDecay weight-decay lists. You need that optimizer and a way for an attacker to set the patterns.

Which version fixes it?

4.53.0. The fix replaces the regex search with a plain substring test.

Does the fix change behaviour?

Yes. The entries in the lists are matched as plain substrings now, so patterns that relied on regex syntax no longer behave as before.

Is it exploited in the wild?

No source we read reports exploitation, and the entry has no CISA KEV record.

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