T09 · Insecure Skill Coding Practices
- Location
main.py:62- Finding
Unescaped Markdown Content Enables HTML and JavaScript Injection
- Content
View full analysis
', text) # Links text = re.sub(r'\[([^\]]+)\]\(([^)]+)\)', r'\1', text) # Bold+italic text = re.sub(r'\*\*\*(.+?)\*\*\*', r'\1', text) # Bold text = re.sub(r'\*\*(.+?)\*\*', r'\1', text) # Italic text = re.sub(r'\*(.+?)\*', r'\1', text) # Inline code text = re.sub(r'`([^`]+)`', r'\1', text) # Strikethrough text = re.sub(r'~~(.+?)~~', r'\1', text) return text ``` The unescaped result is inserted into multiple HTML contexts: ```python html_lines.append(f'{inline(m.group(2))}') ``` ```python html_lines.append(f'
') ``` ```python html_lines.append(f'{inline(text)}
- {inline(m.group(1))}
') ``` ```python html_lines.append(inline(stripped)) ``` ### Technical Analysis The converter treats Markdown input as untrusted source data but does not HTML-escape ordinary text before embedding it in the generated document. Consequently, raw HTML elements and event-handler attributes pass through to the output. The image and link substitutions introduce additional injection contexts: - Image URLs are inserted directly into the `src` attribute. - Image alternative text is inserted directly into the `alt` attribute. - Link destinations are inserted directly into the `href` attribute. - Link text is inserted directly into the element body. - No URI-scheme allowlist prevents dangerous destinations such as `javascript:` or potentially dangerous `data:` content. For example, the following Markdown is copied into a paragraph without neutralization: ```markdown- Remediation
View remediation
` elements. - Event-handler attributes such as `onerror`. - Quotes in image alt text and URLs. - `javascript:` and unsafe `data:` links. - Encoded or control-character-obfuscated URI schemes. - Injection through headings, blockquotes, list items, and paragraphs. ]]>
