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

CVE-2025-6638: Hugging Face Transformers is vulnerable to ReDoS through its MarianTokenizer

mediumCVSS 3.0 5.3GHSA-59p9-h35m-wg4g

Hugging Face Transformers before 4.53.0 has a regular expression denial of service in MarianTokenizer.remove_language_code(). A crafted string with a malformed language code pattern makes the tokenizer spend excessive CPU time. Services that tokenize untrusted text for Marian translation models are affected. Upgrade to transformers 4.53.0.

Published Sep 12, 2025 · Updated Sep 15, 2025 · Analysis Nov 1, 2026

What an attacker can do

MarianTokenizer strips a leading language code written as >>xx<< from the input text. The old implementation did this with a compiled pattern, language_code_re, built from the regex module. Input with malformed language code markers can drive that pattern into slow matching, so one request ties up a CPU core.

The attacker needs to reach a code path that passes their text to a MarianTokenizer, such as a public translation endpoint built on a Marian model. No login is required if the endpoint is open. The result is a slowdown or outage of the worker, not data exposure or code execution. The CVSS 3.0 vector shows network access, no privileges, no interaction and low availability impact.

The fix replaces the pattern with plain string operations, so the cost no longer depends on regex backtracking.

Who is affected

Affected: transformers below 4.53.0, in applications that use MarianTokenizer, for instance with the Helsinki-NLP opus-mt translation models, on untrusted input. Check the installed version:

pip show transformers

Check container images and lock files too, since model-serving images often pin the library.

transformers

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

How to fix it

Upgrade to transformers 4.53.0.

pip install --upgrade transformers==4.53.0

The fix commit removes the regex dependency from the Marian tokenizer. remove_language_code now checks whether the text starts with >> and looks for the closing <<, then slices the code off. It no longer removes language codes found elsewhere in the text. The sources name no other workaround. If you cannot upgrade, limit input length and add a request timeout in front of the tokenizer.

How to tell if you were hit

Look for translation requests with long strings full of >> or << markers, followed by CPU saturation and slow responses on the worker. A Python stack sample inside MarianTokenizer.remove_language_code points to this issue. Compare per-request tokenization time against your baseline.

Original advisory

From the GitHub Advisory Database (CC BY 4.0).

A Regular Expression Denial of Service (ReDoS) vulnerability was discovered in the Hugging Face Transformers library, specifically affecting the MarianTokenizer's remove_language_code() method. This vulnerability is present in version 4.52.4 and has been fixed in version 4.53.0. The issue arises from inefficient regex processing, which can be exploited by crafted input strings containing malformed language code patterns, leading to excessive CPU consumption and potential denial of service.

Questions

Which version fixes CVE-2025-6638?

transformers 4.53.0. The advisory describes version 4.52.4 as vulnerable, and its range is everything below 4.53.0.

Is only the Marian tokenizer affected?

This advisory covers MarianTokenizer.remove_language_code. A separate entry, CVE-2025-6051, covers the EnglishNormalizer number normalization in the same library.

Can it lead to code execution?

No. It is a CPU exhaustion problem from slow regex matching, rated Medium with low availability impact.

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