CVE-2025-6638: Hugging Face Transformers is vulnerable to ReDoS through its MarianTokenizer
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 transformersCheck 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.0The 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 entriesCVE-2026-80047
Hugging Face Transformers downloads custom generation code before trust consent
high7.8No fixSep 1, 2026CVE-2026-9856
Transformers save_pretrained path traversal allows arbitrary file writes through chat template names
high7.1Aug 2, 2026CVE-2026-5241
huggingface/transformers: Arbitrary Code Execution During Model Initialization in the LightGlue Model Loading Path
high8.0Jun 3, 2026CVE-2026-4372
HuggingFace transformers vulnerable to remote code execution
high7.8May 26, 2026CVE-2026-1839
HuggingFace Transformers allows for arbitrary code execution in the `Trainer` class
medium6.5Apr 7, 2026CVE-2025-6921
Hugging Face Transformers vulnerable to Regular Expression Denial of Service (ReDoS) in the AdamWeightDecay optimizer
medium5.3Sep 23, 2025
