Kestrel
대시보드로 돌아가기
CVE-2026-59925HIGH· 7.5MITRENVDGHSA대응게시일: 2026. 07. 08.수정일: 2026. 07. 20.

Mistune inline_parser: quadratic-time parsing on long runs of `**x**` and `***x***` emphasis pairs

위협 신호 · CVSS · EPSS · KEV

정기 패치· 높은 악용 신호 없음
CVSS
7.5high

이론적 심각도 점수

EPSS
0.4%상위 66.5%

30일 내 악용 확률 예측

KEV
미등재

실측 악용 기록 없음

권장 대응 기한14일 이내CISA SSVC 기준

2주 이내 패치 — 우선 조치 대상

자동화 가능외부 노출· KEV 미등재 · 자동화 가능 · 부분 영향 · 외부 노출

CVSS 벡터 · 메트릭

악용 경로
공격 벡터네트워크
공격 복잡도낮음
필요 권한불필요
사용자 상호작용불필요
범위불변
영향
기밀성 영향없음
무결성 영향없음
가용성 영향높음
버전별 점수
CVSS 3.17.5HIGH
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H

상세 설명

Summary

Type: Algorithmic-complexity DoS in core emphasis parsing. A long sequence of well-formed **x** (strong) or ***x*** (strong-emphasis combined) pairs causes O(N²) parser work. Distinct from the bracket-bomb DoS ([ repetition) and from the formatting-plugin DoS (~~/==/^^); this one fires on default-config mistune with no plugins required.
File: src/mistune/inline_parser.py lines 41-48 (the EMPHASIS_END_RE family) and the surrounding emphasis dispatch.
Root cause: for every opening run of *s the parser scans forward using one of EMPHASIS_END_RE['*'] / ['**'] / ['***'] to find the matching close. Each scan is bounded per call, but the parser invokes the scan from every potential start position. For input shaped **x** repeated N times, every ** is treated as a potential start, each scan can cover up to the end of input. Total work is O(N²). The triple-emphasis variant ***x*** is slightly worse due to the extra alternation between *, **, and *** close patterns. Reproducible against default mistune with no plugins.

Affected Code

File: src/mistune/inline_parser.py, lines 41-48.

bash
1EMPHASIS_END_RE = {
2 "*": re.compile(r"(?:" + PREVENT_BACKSLASH + r"\\\*|[^\s*])\*(?!\*)"),
3 "_": re.compile(r"(?:" + PREVENT_BACKSLASH + r"\\_|[^\s_])_(?!_)\b"),
4 "**": re.compile(r"(?:" + PREVENT_BACKSLASH + r"\\\*|[^\s*])\*\*(?!\*)"),
5 "__": re.compile(r"(?:" + PREVENT_BACKSLASH + r"\\_|[^\s_])__(?!_)\b"),
6 "***": re.compile(r"(?:" + PREVENT_BACKSLASH + r"\\\*|[^\s*])\*\*\*(?!\*)"),
7 "___": re.compile(r"(?:" + PREVENT_BACKSLASH + r"\\_|[^\s_])___(?!_)\b"),
8}
9# Each of the six end-patterns is invoked from every emphasis open position
10# fired by the inline rule `r"\*{1,3}(?=[^\s*])|\b_{1,3}(?=[^\s_])"`. The
11# scan itself is bounded per call; the cost comes from the parser invoking
12# the scan at every matching open marker, giving O(N²) total work.

Why it's wrong: same shape as the formatting-plugin and bracket-bomb DoS findings. The CommonMark reference parser handles emphasis in linear time using a delimiter-stack algorithm (commonmark.js, commonmark-py, markdown-it-py all do this). mistune retries the close-scan from each open marker. The bounded regex is not enough; the surrounding loop is the source of the quadratic.

Exploit Chain

  1. Application uses mistune to render user-supplied markdown. No plugins required — affects the default mistune.create_markdown() configuration.
  2. Attacker submits a 40 KB payload of **x** repeated 8000 times.
  3. Server CPU pegs for ~4 seconds; 16 KB → ~17 seconds. Doubling input quadruples time.
  4. Repeating the request floods the worker pool.

Security Impact

Severity: sec-high. Network-reachable, no authentication, no plugin requirement. Default mistune is vulnerable.
Attacker capability: O(N²) CPU cost from a single small input. Predictable scaling, easy to combine with concurrent requests for service denial.
Preconditions: application uses mistune.create_markdown() (default config) on attacker-supplied markdown. No plugins required.
Differential: PoC-verified against mistune@3.2.1, default config:

python
1import mistune, time
2md = mistune.create_markdown() # no plugins
3for n in [500, 1000, 2000, 4000, 8000]:
4 s = '**x**' * n
5 t = time.time()
6 md(s)
7 print(f' **x** * {n} ({len(s)}b): {(time.time() - t) * 1000:.0f}ms')
8
9# Output (Python 3.13, Linux, 2.5GHz CPU):
10# **x** * 500 (2500b): 20ms
11# **x** * 1000 (5000b): 74ms
12# **x** * 2000 (10000b): 284ms
13# **x** * 4000 (20000b): 1079ms
14# **x** * 8000 (40000b): 4309ms
15
16# Triple-emphasis is similar:
17md('***x***' * 4000) # ~1500ms
18
19# Linear in N for non-emphasis input of comparable size:
20md('xxxxx' * 8000) # 1ms (4000x faster)

The patched build (with the suggested fix below — delimiter-stack rewrite or hard cap on simultaneous open markers) keeps the time linear in N.

Suggested Fix

Cap the number of unmatched opening emphasis markers the parser will track simultaneously, treating the rest as literal text:

bash
1--- a/src/mistune/inline_parser.py
2+++ b/src/mistune/inline_parser.py
3@@ ... in the emphasis-handling code path
4+ # Bound the number of open emphasis markers tracked. CommonMark gives
5+ # no semantics to deeply nested unmatched emphasis; this cap turns the
6+ # parser-level O(N^2) into O(N) for adversarial inputs while preserving
7+ # behaviour on every realistic markdown document.
8+ MAX_OPEN_EMPHASIS = 100
9+ if open_emphasis_count > MAX_OPEN_EMPHASIS:
10+ # treat remaining * / _ as literal text
11+ ...

The proper fix is a delimiter-stack pass, the same approach the formatting-plugin advisory and the bracket-bomb advisory recommend. All three DoS findings share the same algorithmic pattern; a single rewrite of the inline-token retry loop closes them together. Add a regression test asserting that md('**x**' * 50_000) completes in under 1 second.

AI 심층 분석

공격 시나리오 · 재현 가능한 PoC 페이로드 · 즉시 적용 가능한 차단 패치를 한 번에 받아 보세요. 보안 운영팀이 그대로 점검·티켓팅에 쓸 수 있는 형태로 정리해 드립니다.