T09 · Insecure Skill Coding Practices
- Location
scripts/format_md.py:123- Finding
Unescaped Markdown Content Enables HTML and Script Injection
- Content
View full analysis
{_inline_format(line)}') ``` ```python def _inline_format(text: str) -> str: """行内格式化: 加粗、斜体、链接、行内代码""" # 加粗 **text** text = re.sub(r'\*\*(.+?)\*\*', r'\1', text) # 斜体 *text* text = re.sub(r'(?\1', text) # 行内代码 `code` text = re.sub(r'`([^`]+)`', r'\1', text) # 链接 [text](url) text = re.sub( r'\[([^\]]+)\]\(([^)]+)\)', r'\1', text ) return text ``` ### Technical Analysis The Markdown-to-HTML conversion passes ordinary Markdown content directly into generated HTML without first applying HTML escaping. The `_inline_format` function performs regular-expression substitutions but does not encode security-sensitive characters such as `<`, `>`, `"`, `'`, and `&`. Consequently, raw HTML supplied through a Markdown paragraph can survive conversion. For example: ```markdown``` The generated output includes this element inside a paragraph, preserving its event handler. Markdown link destinations are also interpolated directly into a double-quoted `href` attribute. An attacker can therefore: 1. Supply a dangerous URL scheme such as `javascript:`. 2. Inject quotation marks into the destination to terminate the `href` value and add another HTML attribute. 3. Place malicious HTML in link labels or other inline-formatted content. The code properly escapes fenced code-block content in `_format_code_block`, but equivalent protection is not applied to ...[truncated 1629 chars]
- Remediation
View remediation
` and `` input. - Quotes embedded in link destinations. - `javascript:` and `data:` links. - HTML embedded in headings, quotations, link labels, and inline code. 8. Document that generated files must not be treated as trusted HTML unless sanitization is enforced. ]]>
