CVE-2026-59922: Mistune plugins/formatting: quadratic-time parsing on long runs of `~~x~~`, `==x==`, and `^^x^^` markers (strikethrough / mark / insert)

Published Jul 8, 2026
·
Updated

Summary

Type: Algorithmic-complexity denial of service. A run of N closed pairs ~~x~~~~x~~... (or the analogous ==x== for mark, ^^x^^ for insert) causes O(N²) work in the formatting parser. With the strikethrough, mark, or insert plugin enabled, an 8 KB input pegs the CPU for ~4 seconds; 16 KB → ~17 seconds. File: src/mistune/plugins/formatting.py, lines 13-15 (the STRIKEEND / MARKEND / INSERTEND patterns and their per-position scan). Root cause: for each opening ~~/==/^^ the parser scans forward for the matching close pattern. The scan itself uses a bounded regex, but the parser tries the close-scan at every potential start position. For input shaped like ~~x~~ repeated N times, every ~~ is examined as a possible start, each scan covers up to the end of input. Total work is O(N²). Default config without these plugins handles the same input in linear time (4 ms for 4000 reps), confirming the cost is in the formatting plugin's per-marker scan, not in core parsing.

Affected Code

File: src/mistune/plugins/formatting.py, lines 12-16.

python STRIKEEND = re.compile(r"(?:" + PREVENTBACKSLASH + r"\\~|[^\s~])~~(?!~)") MARKEND = re.compile(r"(?:" + PREVENTBACKSLASH + r"\\=|[^\s=])==(?!=)") INSERTEND = re.compile(r"(?:" + PREVENTBACKSLASH + r"\\\^|[^\s^])\^\^(?!\^)") Each pattern is scanned forward from every start position fired by the corresponding inline rule. The end-pattern itself is bounded; the cost comes from the surrounding parser invoking the scan at every '~~' / '==' / '^^' token in the input, giving N starts × O(N) per scan = O(N^2) total.

Why it's wrong: the same algorithmic-complexity flaw class as [ / [a parsing in core: a per-token retry loop without memoisation of failed positions. Each formatting marker is tried as both a potential start and as a continuation. A linear-pass delimiter-stack algorithm (matching how commonmark-py and markdown-it-py handle emphasis) would do this work in O(N) total. The bounded regex on each individual scan does not bound the parser-level repetition.

Exploit Chain

1. Application uses mistune to render user-supplied markdown and has any of the formatting plugins enabled (plugins=['strikethrough'], ['mark'], ['insert'], or any superset). These plugins are commonly enabled because GitHub-flavoured-Markdown compatibility requires ~~strikethrough~~ and many editors emit ==highlighting== and ^^underline^^ shortcuts. 2. Attacker submits an 8 KB markdown payload of the form ~~x~~~~x~~~~x~~... (40 000 characters of ~~x~~ repeated 8000 times, or the analogous shape with == / ^^). 3. Server calls mistune.createmarkdown(plugins=['strikethrough'])(payload). CPU pegs for ~4 seconds; 16 KB → ~17 seconds; 32 KB → ~70 seconds. Pure CPU cost, no significant memory growth. 4. Repeating the request floods the worker pool. On a single-thread WSGI handler this is one request per outage; on a thread pool, a small number of concurrent attackers exhausts capacity.

Security Impact

Severity: sec-high. Network-reachable, no authentication, predictable scaling, single-payload primitive. Only requires a user-supplied markdown sink and a formatting plugin enabled — both are common. Attacker capability: small input → large CPU. Doubling input size quadruples CPU time. Sustained requests deny service to other users. Preconditions: application uses mistune with any of strikethrough, mark, or insert plugins enabled. Default config does NOT enable these (so the attack only fires against the substantial deployed population that turns them on for GFM/markdown-extra compatibility). Differential: PoC-verified against mistune@3.2.1:

python import mistune, time md = mistune.createmarkdown(plugins=['strikethrough']) for n in [500, 1000, 2000, 4000, 8000]: s = '~~x~~' n t = time.time() md(s) print(f' ~~x~~ {n} ({len(s)}b): {(time.time() - t) 1000:.0f}ms')

Output (Python 3.13, Linux, 2.5GHz CPU): ~~x~~ 500 (2500b): 19ms ~~x~~ 1000 (5000b): 71ms ~~x~~ 2000 (10000b): 272ms ~~x~~ 4000 (20000b): 1090ms ~~x~~ 8000 (40000b): 4302ms

Identical scaling for ==x== (mark) and ^^x^^ (insert): md = mistune.createmarkdown(plugins=['mark']) md('==x==' 4000) # ~1100ms md = mistune.createmarkdown(plugins=['insert']) md('^^x^^' 4000) # ~1080ms

Without the plugin, the same input parses in linear time: md = mistune.createmarkdown() # no plugins md('~~x~~' 4000) # 4ms (1000x faster)

The patched build (with the suggested fix below — either a delimiter-stack rewrite or a hard cap on the number of unmatched markers tracked) keeps the time linear in N.

Suggested Fix

The minimal fix is to cap the number of simultaneously-tracked unmatched markers, treating extras as literal text. The proper fix is a single-pass delimiter-stack algorithm matching the CommonMark reference implementation. Surgical patch:

diff --- a/src/mistune/plugins/formatting.py +++ b/src/mistune/plugins/formatting.py @@ ... in the parsestrikethrough / parsemark / parseinsert functions + # Bound the number of open markers the parser will track concurrently. + # Inputs with more than this many open ~~ / == / ^^ in flight are + # almost certainly adversarial; CommonMark gives no semantics to + # deeply nested unmatched markers. + MAXOPENMARKERS = 100 + if openmarkercount > MAXOPENMARKERS: + # treat remaining markers as literal text, do not invoke the + # forward-scan to find a close + ...

A regression test should assert that md('~~x~~' 50000) completes in under 1 second. The same fix shape applies to MARKEND and INSERTEND.

Other sources

Mistune is a Python Markdown parser with renderers and plugins. Prior to 3.3.0, a run of closed tilde, equals-sign, or caret marker pairs around a character causes quadratic work in src/mistune/plugins/formatting.py when the strikethrough, mark, or insert plugin scans for matching markers from each possible start position, allowing denial of service through CPU exhaustion. This issue is fixed in version 3.3.0.

MITRE

Affected Software

3 affected componentsFixes available
Mistune Mistune<3.3.0
Mistune Project Mistune<3.3.0
pip/mistune<3.3.0
3.3.0

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade pip/mistune to a version that resolves this vulnerability.

    Fixed in 3.3.0
  2. Upgrade

    Upgrade mistune to a version that resolves this vulnerability.

    Fixed in 3.3.0
  3. Configuration

    In src/mistune/plugins/formatting.py, cap concurrently tracked unmatched markers by setting MAX_OPEN_MARKERS = 100; if open_marker_count exceeds MAX_OPEN_MARKERS, treat additional opening markers as literal text instead of continuing to scan for their matching close patterns.

    mistune/plugins/formatting.py (strikethrough/mark/insert plugin parsing) MAX_OPEN_MARKERS = 100

Event History

Jul 8, 2026
CVE Published
via MITRE·04:12 PM
Data Sourced
via MITRE·04:12 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·05:17 PM
RemedyDescriptionSeverityWeaknessAffected Software
Jul 20, 2026
Advisory Published
via GitHub·09:34 PM
Data Sourced
via GitHub·09:34 PM
DescriptionSeverityWeaknessAffected Software

Frequently Asked Questions

1

What is the severity of CVE-2026-59922?

The severity of CVE-2026-59922 is high with a score of 7.5.

2

What impact does CVE-2026-59922 have on affected systems?

CVE-2026-59922 can lead to denial of service due to quadratic-time parsing on long runs of certain Markdown markers.

3

How do I fix CVE-2026-59922?

To fix CVE-2026-59922, update Mistune to version 3.3.0 or later.

4

What software is affected by CVE-2026-59922?

CVE-2026-59922 affects the Mistune Markdown parser prior to version 3.3.0.

5

When was CVE-2026-59922 published?

CVE-2026-59922 was published on July 8, 2026.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203