Mistune: Denial of Service — RecursionError via Excessive Emphasis Markers in Markdown
概要
Mistune: Denial of Service — RecursionError via Excessive Emphasis Markers in Markdown
原文の説明
取得元が公開している説明をそのまま載せています (多くは英語)。
Summary
Mistune v3.3.2 is vulnerable to a Denial of Service (DoS) attack via uncontrolled recursion in the HTML rendering of deeply-nested emphasis tokens. By submitting Markdown containing approximately 1,000 consecutive asterisk characters, an attacker causes the Python process to crash with RecursionError.
Details
The InlineParser's _process_emphasis_delimiters() creates deeply nested tokens from consecutive emphasis markers (every 2 asterisks add one nesting level). With 1,000 consecutive asterisks, approximately 500 levels of nesting are produced. The HTMLRenderer.render_token() method (src/mistune/renderers/html.py:40-57) renders these tokens recursively: when a token has children, line 48 calls self.render_tokens(token['children'], state), entering child rendering. Each nesting level produces ~2 stack frames, so 500 levels ≈ 1,000 frames, exceeding Python's default recursion limit (sys.getrecursionlimit() = 1000). The emphasis() and strong() methods (lines 80-84) wrap recursively rendered child content in and tags, perpetuating the recursion. This vulnerability affects all mistune APIs including markdown() and html().
Core vulnerable code path:
# src/mistune/renderers/html.py:40-57
def render_token(self, token: Dict[str, Any], state: BlockState) -> str:
func = self._get_method(token["type"])
attrs = token.get("attrs")
if "raw" in token:
text = token["raw"]
elif "children" in token:
text = self.render_tokens(token["c…
出典: NIST National Vulnerability Database NVD GitHub Advisory
AI要約
外部の AI が作成した要約です。誤りを含むことがあります。重要な判断の前に、下の原文と参照URLを確認してください。
Mistuneのバージョン3.3.0から3.3.2には、深くネストされたトークンによるDoSの脆弱性があります。HTMLレンダリング中に発生する再帰レンダリングがPythonの再帰制限を超え、RecursionErrorを引き起こす可能性があります。この問題はバージョン3.3.3で修正されています。
MistuneのMarkdownパーサーが、深くネストされたトークンによるDoSの影響を受ける。
バージョン3.3.0から3.3.2のMistune
HTMLレンダリングがPythonの再帰制限を超えクラッシュを引き起こすため、高い影響がある。
バージョン3.3.3にアップデートする。
一時的にMarkdown解析の深さを制限する。
Markdownファイルを解析し、深くネストされたトークンの存在を確認する。
影響パッケージ
参照URL
- web security-advisories@github.com
- web github.com
- web nvd.nist.gov
- web github.com
- web github.com
- web github.com