T09 · Insecure Skill Coding Practices
- Location
references/libraries.md:174- Finding
Unsanitized Markdown Rendering Enables Client-Side HTML Injection
- Content
View full analysis
``` ### Technical Analysis The example parses `mdText` with `marked.parse()` and assigns the resulting string directly to the DOM through `innerHTML`. Marked is a Markdown parser, not an HTML sanitizer. Depending on its configuration, embedded HTML and dangerous attributes in the source Markdown can remain in the rendered output. If `mdText` contains user-controlled educational material, an attacker can insert elements with executable event handlers, dangerous URL schemes, malicious forms, or embedded external content. Although script elements inserted through `innerHTML` are not reliably executed by browsers, event-handler payloads such as an image `onerror` handler can execute when the generated page is opened. This is especially relevant because the Skill is explicitly intended to transform user-provided teaching text into a browser-openable HTML file. ### Attack Path 1. An attacker supplies educational Markdown containing malicious HTML, for example: ```html``` 2. The content is placed into the `mdText` variable without sanitization. 3. `marked.parse(mdText)` preserves or emits the malicious HTML. 4. The result is assigned to `article.innerHTML`. ...[truncated 959 chars]
- Remediation
View remediation
``` 2. If raw HTML is not required, configure the rendering pipeline to reject or escape embedded HTML. 3. Use `textContent` instead of `innerHTML` wherever rich HTML rendering is unnecessary. 4. Restrict dangerous URL schemes and remove event-handler attributes, forms, iframes, embedded objects, and unnecessary external-resource elements. 5. Add regression tests covering at least: - `` - `` - Links using the `javascript:` scheme - Malicious iframes and forms - Encoded or mixed-case variants of dangerous attributes 6. Add a restrictive Content Security Policy to generated pages as defense in depth. Do not treat CSP as a substitute for sanitization. ]]>
