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

Mistune renderers/html.safe_url: HARMFUL_PROTOCOLS list misses legacy and chained schemes that historically chain to `javascript:` execution

XSS

위협 신호 · CVSS · EPSS · KEV

정기 패치· 높은 악용 신호 없음
CVSS
6.1medium

이론적 심각도 점수

EPSS
0.2%상위 86.6%

30일 내 악용 확률 예측

KEV
미등재

실측 악용 기록 없음

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

계획된 패치 주기 내 조치(60일 이내)

외부 노출· KEV 미등재 · 자동화 어려움 · 부분 영향 · 외부 노출

CVSS 벡터 · 메트릭

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

상세 설명

Summary

Type: URL-scheme allowlist gap. The safe_url filter only blocks the four schemes javascript:, vbscript:, file:, data:. Several other schemes are accepted into rendered <a href="..."> and <img src="..."> tags despite being known XSS vectors in legacy or chain-handling browsers. The same gap applies to direct links, reference links, and autolinks.
File: src/mistune/renderers/html.py, line 11-23 (HARMFUL_PROTOCOLS list).
Root cause: the HARMFUL_PROTOCOLS tuple is a hardcoded, opt-out denylist of four entries. Browsers historically supported (and some still partially support) several other schemes that either execute JavaScript directly (livescript:, mocha:) or wrap a javascript: payload (feed:javascript:, view-source:javascript:, jar:javascript:, ms-its:javascript:, mk:@MSITStore:javascript:). On user-agents that still recognise these schemes (older Firefox builds for feed:/jar:, all Internet Explorer / Edge Legacy for ms-its:/mk:/res:, niche chrome-style browsers, browser extensions that register custom protocol handlers), clicking a link rendered by mistune executes attacker-controlled JavaScript in the page's origin.

Affected Code

File: src/mistune/renderers/html.py, lines 10-62.

xss
1class HTMLRenderer(BaseRenderer):
2 HARMFUL_PROTOCOLS: ClassVar[Tuple[str, ...]] = (
3 "javascript:",
4 "vbscript:",
5 "file:",
6 "data:",
7 ) # <-- BUG: incomplete denylist
8 GOOD_DATA_PROTOCOLS: ClassVar[Tuple[str, ...]] = (
9 "data:image/gif;",
10 "data:image/png;",
11 "data:image/jpeg;",
12 "data:image/webp;",
13 )
14
15 def safe_url(self, url: str) -> str:
16 if self._allow_harmful_protocols is True:
17 return escape_text(url)
18 _url = url.lower()
19 if self._allow_harmful_protocols and _url.startswith(tuple(self._allow_harmful_protocols)):
20 return escape_text(url)
21 if _url.startswith(self.HARMFUL_PROTOCOLS) and not _url.startswith(self.GOOD_DATA_PROTOCOLS):
22 return "#harmful-link"
23 return escape_text(url) # <-- BUG: any scheme not in HARMFUL_PROTOCOLS passes through

Why it's wrong: an opt-out denylist for URL schemes is the wrong shape. The set of schemes a user-agent might honour is unbounded (registered handlers, browser extensions, OS-level protocol registrations, custom intent handlers on Android, etc.), but the set of schemes a markdown renderer needs to allow is small (http://, https://, mailto:, optionally tel:, ftp:, fragment-only #anchor, and a few image-only data: types). Switching to an opt-in allowlist with a safe_extra_protocols knob for callers who need others would close every variant of this bug class permanently. The current code accepts every chained-scheme XSS vector for as long as the project remembers to keep the denylist current.

Exploit Chain

  1. Application accepts attacker-supplied markdown and renders it with mistune. The default escape=True prevents raw HTML, but link href/image src filtering is the only XSS defense for [click](...) and ![alt](...) syntax.
  2. Attacker writes [click here](feed:javascript:alert(document.cookie)). mistune's safe_url checks feed:javascript:alert(document.cookie) against HARMFUL_PROTOCOLS = ('javascript:', 'vbscript:', 'file:', 'data:') — none match. The href is escape_text'd (HTML-entity escape) and emitted as <a href="feed:javascript:alert(document.cookie)">click here</a>.
  3. Victim using a Firefox build that still has the feed handler registered (extension, configuration, or LTS that retained the feed reader past the 64.0 removal — including some forks and ESR builds) clicks the link. Firefox's feed handler invokes the inner URL, which is javascript:alert(...). JS executes in the page's origin. Victim's session cookie is exfiltrated.
  4. Same pattern for livescript:alert(1) (Netscape Communicator era, still recognised by some niche browsers / browser-emulator tools), view-source:javascript:alert(1) (Firefox, see CVE-2009-1938), jar:javascript:alert(1) (older Firefox), ms-its:javascript: (IE/Edge Legacy), res:javascript: (IE), mk:@MSITStore:javascript: (IE CHM viewer). Each user-agent that recognises one of these is exploitable; the user-agent population that recognises at least one is not negligible (corporate environments still running Edge Legacy compatibility mode, locked-down kiosk browsers, Android WebView in apps that register custom intent handlers, Linux distros with old Firefox ESR plus the feed: extension, etc.).

The same primitive applies to image src (![](feed:javascript:...) rendered as <img src="feed:...">) — though most browsers don't fetch javascript: from img src, the same chained handler quirk applies on a few user-agents — and to reference links and autolinks (verified in the PoC below; the rendered HTML is identical regardless of which markdown link syntax is used).

Security Impact

Severity: sec-moderate. Conditional XSS depending on user-agent. Modern Chrome / Edge Chromium / Safari ignore most of these schemes, but Firefox forks, Edge Legacy, in-app WebViews, browser extensions registering custom handlers, and corporate browser deployments are exposed. Defence-in-depth is the framing: a markdown renderer should not need to track which browsers still honour which legacy chained-scheme.
Attacker capability: plant a link in any place the application renders user-supplied markdown. When clicked by a user-agent that honours the legacy scheme, the attacker's JavaScript runs in the page's origin (steal cookies, perform actions as the victim, etc.).
Preconditions: application uses mistune to render attacker-influenced markdown. Default config. Victim user-agent is one of the affected populations. No specific mistune option is required.
Differential: PoC-verified against mistune@3.2.1, default config. The following inputs all PASS the filter and reach the rendered HTML unchanged:

xss
1import mistune
2md = mistune.create_markdown()
3for url in [
4 'feed:javascript:alert(1)', # Firefox feed handler chain
5 'livescript:alert(1)', # Netscape, niche browsers
6 'mocha:alert(1)', # Netscape, niche browsers
7 'view-source:javascript:alert(1)', # Firefox view-source chain (CVE-2009-1938 class)
8 'jar:javascript:alert(1)', # Firefox jar: handler chain
9 'ms-its:javascript:alert(1)', # IE/Edge Legacy InfoTech Storage handler
10 'mk:@MSITStore:javascript:alert(1)', # IE CHM viewer chain
11 'res:javascript:', # IE resource: handler
12]:
13 print(md(f'[click]({url})').strip())
14
15# Output (each one passes the filter):
16# <p><a href="feed:javascript:alert(1)">click</a></p>
17# <p><a href="livescript:alert(1)">click</a></p>
18# <p><a href="mocha:alert(1)">click</a></p>
19# <p><a href="view-source:javascript:alert(1)">click</a></p>
20# <p><a href="jar:javascript:alert(1)">click</a></p>
21# <p><a href="ms-its:javascript:alert(1)">click</a></p>
22# <p><a href="mk:@MSITStore:javascript:">click</a></p>
23# <p><a href="res:javascript:">click</a></p>

For comparison, the four schemes already in the denylist are correctly blocked: javascript:, vbscript:, file:, data:text/html all return <a href="#harmful-link">.

The same gap applies to reference links ([click][ref]\n\n[ref]: feed:javascript:alert(1)<a href="feed:javascript:alert(1)">) and to autolinks (<feed:javascript:alert(1)><a href="feed:javascript:alert(1)">).

Suggested Fix

Switch from denylist to allowlist. The set of schemes a markdown renderer needs to allow is small and well-known; the set of schemes that might trigger handler chains is unbounded.

xss
1--- a/src/mistune/renderers/html.py
2+++ b/src/mistune/renderers/html.py
3@@ -7,21 +7,28 @@ class HTMLRenderer(BaseRenderer):
4
5 _escape: bool
6 NAME: ClassVar[Literal["html"]] = "html"
7- HARMFUL_PROTOCOLS: ClassVar[Tuple[str, ...]] = (
8- "javascript:",
9- "vbscript:",
10- "file:",
11- "data:",
12- )
13+ SAFE_PROTOCOLS: ClassVar[Tuple[str, ...]] = (
14+ "http:",
15+ "https:",
16+ "mailto:",
17+ "tel:",
18+ "ftp:",
19+ "ftps:",
20+ "irc:",
21+ "ircs:",
22+ )
23 GOOD_DATA_PROTOCOLS: ClassVar[Tuple[str, ...]] = (
24 "data:image/gif;",
25 "data:image/png;",
26 "data:image/jpeg;",
27 "data:image/webp;",
28 )
29
30@@ -49,15 +56,21 @@ class HTMLRenderer(BaseRenderer):
31 def safe_url(self, url: str) -> str:
32- if self._allow_harmful_protocols is True:
33- return escape_text(url)
34-
35- _url = url.lower()
36- if self._allow_harmful_protocols and _url.startswith(tuple(self._allow_harmful_protocols)):
37- return escape_text(url)
38-
39- if _url.startswith(self.HARMFUL_PROTOCOLS) and not _url.startswith(self.GOOD_DATA_PROTOCOLS):
40- return "#harmful-link"
41- return escape_text(url)
42+ # Allow-list: only schemes in SAFE_PROTOCOLS, image-only data: URLs in
43+ # GOOD_DATA_PROTOCOLS, scheme-relative URLs (//host/path), absolute
44+ # paths (/path), and anchor-only references (#fragment) reach the
45+ # rendered output. Everything else is replaced with '#harmful-link'.
46+ if self._allow_harmful_protocols is True:
47+ return escape_text(url)
48+ _url = url.lower().lstrip()
49+ if (
50+ _url.startswith(self.SAFE_PROTOCOLS)
51+ or _url.startswith(self.GOOD_DATA_PROTOCOLS)
52+ or _url.startswith(("/", "#", "?"))
53+ or ":" not in _url.split("/", 1)[0] # bare relative path
54+ ):
55+ return escape_text(url)
56+ if self._allow_harmful_protocols and _url.startswith(tuple(self._allow_harmful_protocols)):
57+ return escape_text(url)
58+ return "#harmful-link"

The allow_harmful_protocols option is preserved, so callers who genuinely want to allow a custom scheme can still opt in. The lower().lstrip() also closes the leading-whitespace evasion sub-case (e.g., javascript: is already blocked by the current code via lower().startswith, but the same pattern needs to apply on the new allowlist branch). Add regression tests for each scheme listed in the PoC above asserting they resolve to #harmful-link.

AI 심층 분석

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