T09 · Insecure Skill Coding Practices
- Location
scripts/md_to_html.py:166- Finding
Stored HTML Injection in Generated Documents
- Content
View full analysis
', text) # links 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) return text ``` The unescaped result is inserted into tables and document content: ```python for cell in table_rows[0]: html.append(f'{parse_inline(cell)}') for row in table_rows[1:]: html.append('') for cell in row: html.append(f'{parse_inline(cell)}') html.append('') ``` ```python output.append(f'{parse_inline(line.strip())}
') ``` The Markdown title is also inserted into multiple HTML contexts without escaping: ```python title_match = re.search(r'^#\s+(.+)$', md_text, re.MULTILINE) title = title_match.group(1) if title_match else os.path.splitext(os.path.basename(input_path))[0] body = convert_md_to_html(md_text) html = HTML_TEMPLATE.format(title=title, content=body) ``` ### Technical Analysis The converter treats attacker-controlled Markdown as trusted HTML. `parse_inline()` performs regular-expression substitutions but never HTML-escapes ordinary text before returning it. As a result, raw HTML elements and event-handler attributes supplied in headings, paragraphs, list items, blockquotes, or table cells remain active in the generated document. Link destinations and image sour ...[truncated 2031 chars]- Remediation
View remediation
` and ``. 4. Validate link and image URL schemes using a URL parser. Permit only explicitly required schemes, such as `https`, `http`, and optionally `mailto`. Reject `javascript:`, unexpected `data:` URLs, embedded control characters, and obfuscated variants. 5. If limited raw HTML support is required, sanitize the rendered output with an allowlist-based HTML sanitizer. Permit only necessary elements and attributes, and remove scripts, event handlers, dangerous URLs, embedded frames, and active content. 6. Add automated regression tests covering: - Raw `
