Skip to content
DoS Disclosed report Intermediate CVE-2025-6921

Hugging Face Transformers vulnerable to Regular Expression Denial of Service (ReDoS) in the AdamWeightDecay optimizer

The AdamWeightDecay optimizer in Hugging Face Transformers processes user-supplied regular expressions in its weight decay include and exclude lists using re.search, which can suffer catastrophic backtracking. An attacker who controls these patterns could cause 100% CPU usage and hang the machine learning task, leading to denial of service.

huggingface/transformers

Originally disclosed on huntr

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.

From the GitHub Advisory Database (GHSA-4w7r-h757-3r74, CC BY 4.0).

The original report as published on the GitHub Advisory Database. Images and videos are our own copies; raw HTML is shown as text. View it on GitHub Advisory Database.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The _do_use_weight_decay method passes user-controlled regular expressions directly to re.search without limiting their complexity, allowing catastrophic backtracking.

Impact

An attacker who can control the patterns could cause 100% CPU utilization and hang the machine learning task, rendering services unresponsive.

What the attacker needed

Attacker controls regex patterns in optimizer lists

The fix

The issue was fixed in version 4.53.0.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A regular expression is a pattern used to match text. Some patterns can make the matching engine try an enormous number of combinations, which is called catastrophic backtracking. Here, if an attacker can supply such a pattern to the optimizer, the program spends all its CPU time on matching and stops doing useful work, so the service becomes unresponsive.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More from huggingface/transformers

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.