CVE-2024-12720: Transformers Regular Expression Denial of Service (ReDoS) vulnerability
The Nougat fast tokenizer in Hugging Face transformers before 4.48.0 has a regular expression with exponential backtracking in `post_process_single()`. Crafted text sent through it pins the CPU and can stall the application. Upgrade to transformers 4.48.0.
Published Mar 20, 2025 · Updated Mar 21, 2025 · Analysis Nov 1, 2026
What an attacker can do
The flaw is in tokenization_nougat_fast.py, in the function post_process_single(), which cleans up text produced by the Nougat OCR model. A regex on the heading-removal line nested one repeated group inside another: ^#+ (?:\.?(?:\d|[ixv])+)*\s*(?:$|\n\s*). A line that starts with # followed by a long run of digits or roman-numeral letters that then fails to match makes the engine try an exponential number of splits. One call can burn a CPU core for a very long time.
The attacker needs to get crafted text into the post-processing step. That happens in services that run Nougat on documents users upload and post-process the output, where the model output can carry the attacker's text from a crafted PDF. The CVSS vector scores low availability impact, network, no privileges. A single worker stalls per request, but a handful of requests can exhaust a small pool. The report names v4.46.3.
Who is affected
The pip package transformers before 4.48.0, in code that uses the Nougat fast tokenizer (NougatTokenizerFast) and calls its post-processing on untrusted input. Services that never use Nougat do not reach this regex.
Check the version:
pip show transformersThen search your code for NougatTokenizerFast and post_process_generation.
transformers
- Ecosystem
- PyPI
- Affected
- < 4.48.0
- Fixed in
- 4.48.0
- Check
pip show transformers
How to fix it
Upgrade to transformers 4.48.0.
pip install -U "transformers>=4.48.0"The fix commit replaces the nested pattern with ^#+ (?:[\d+\.]+|[ixv\.]+)?\s*(?:$|\n\s*), which has no nested repetition and so cannot backtrack exponentially. The sources name no workaround. If you cannot upgrade, run Nougat post-processing in a worker with a timeout.
How to tell if you were hit
Look for Python workers stuck at 100 percent CPU inside post_process_single in tokenization_nougat_fast.py, for example in py-spy dump output, and requests to OCR or document endpoints that never return. Check request logs for uploads that precede the stall.
Original advisory
From the GitHub Advisory Database (CC BY 4.0).
A Regular Expression Denial of Service (ReDoS) vulnerability was identified in the huggingface/transformers library, specifically in the file tokenization_nougat_fast.py. The vulnerability occurs in the post_process_single() function, where a regular expression processes specially crafted input. The issue stems from the regex exhibiting exponential time complexity under certain conditions, leading to excessive backtracking. This can result in significantly high CPU usage and potential application downtime, effectively creating a Denial of Service (DoS) scenario. The affected version is v4.46.3.
Questions
- Does CVE-2024-12720 affect all transformers users?
Only code that reaches the Nougat fast tokenizer's
post_process_single(). Other tokenizers and models are not named by the advisory.- Which version fixes it?
4.48.0. The advisory lists versions below 4.48.0 as vulnerable and names v4.46.3 in the report.
- Can it execute code or leak data?
No. It is a regular expression denial of service that causes high CPU use and downtime.
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
