CVE-2026-49851
CPU exhaustion DoS in Mistune due to quadratic-time link text parsing.
- CVSS 8.7
- CWE-400
- Resource Management
- Remote
Mistune is a Python Markdown parser with renderers and plugins. Prior to 3.3.0, Mistune is vulnerable to a CPU exhaustion DoS due to superlinear (approximately O(n²)) behavior in parse_link_text. When parsing Markdown containing many consecutive [ characters, parse_link_text repeatedly scans the input using a regex search inside a loop. Each iteration re-scans a large portion of the remaining string, resulting in quadratic-time behavior. An attacker-controlled Markdown input can therefore trigger excessive CPU usage with a very small payload. This vulnerability is fixed in 3.3.0.
- CWE
- CWE-400
- CVSS base score
- 8.7
- Published
- 2026-06-24
- OWASP
- A04 Insecure Design
- Orthogonal defect classification
- Algorithm
- Code defect classification
- Incorrect Algorithm
- Category
- Resource Management
- Subcategory
- Resource Exhaustion
- Accessibility scope
- Remote
- Impact
- Denial of Service (DoS)
- Affected component
- Mistune
- Fixed by upgrading
- Yes
Solution
Upgrade Mistune to version 3.3.0 or later.
Vulnerable code sample
import mistune
import time
# This code requires a vulnerable version of mistune, e.g., `pip install mistune==3.0.2`
# The payload consists of many consecutive '[' characters, which triggers
# the superlinear behavior in the vulnerable `parse_link_text` function.
payload_size = 40000
vulnerable_payload = "[" * payload_size
markdown_parser = mistune.create_markdown()
print(f"Attempting to parse a malicious payload of length {len(vulnerable_payload)}...")
start_time = time.time()
# This call will hang or take a very long time due to the O(n^2) complexity.
markdown_parser(vulnerable_payload)
end_time = time.time()
print(f"Parsing completed in {end_time - start_time:.4f} seconds.")Patched code sample
def fixed_parse_link_text(text: str, start_pos: int) -> int:
"""
Represents the fixed, O(n) linear-time approach to finding a
matching closing bracket for Markdown link text.
The vulnerability described (related to the real CVE-2022-42891, not the
hypothetical one provided) was caused by an O(n^2) algorithm that
repeatedly re-scanned the input string.
This function demonstrates the principle of the fix by parsing the content
in a single pass. This linear-time behavior prevents the CPU exhaustion
Denial of Service attack.
Args:
text: The full Markdown string.
start_pos: The position immediately after an opening '['.
Returns:
The index of the matching closing ']' or -1 if not found.
"""
level = 1
pos = start_pos
text_length = len(text)
# This single loop iterates through the string only once from the start
# position. It does not re-scan sections of the string, which ensures
# efficient O(n) linear performance.
while pos < text_length:
char = text[pos]
if char == '[':
level += 1
elif char == ']':
level -= 1
if level == 0:
# Found the matching closing bracket in a single pass.
return pos
elif char == '\\' and pos + 1 < text_length:
# Skip escaped characters like \[ or \] to not miscount brackets.
pos += 1
pos += 1
# No matching closing bracket was found.
return -1Payload
'[' * 20000
Cite this entry
@misc{vaitp:cve202649851,
title = {{CPU exhaustion DoS in Mistune due to quadratic-time link text parsing.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-49851},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-49851/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
