T09 · Insecure Skill Coding Practices
Warning
- Location
- SKILL.md:97
- Finding
- Unsanitized Markdown HTML May Execute Active Content in the Browser Renderer<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md:97-100`, `templates/card-template.html:261-264`, and `references/browser-screenshot-spec.md:12-19` **Vulnerability Type**: Active-content injection through unsanitized Markdown HTML **Risk Level**: Medium ### Vulnerable Code and Configuration `SKILL.md:97-100` enables Markdown processing extensions that include raw HTML support: ```markdown ### 2. Markdown to HTML Use `python-markdown` with extensions: - `tables`, `fenced_code`, `codehilite`, `nl2br`, `sane_lists`, `smarty`, `attr_list`, `md_in_html`, `toc` ``` `templates/card-template.html:261-264` inserts the generated card markup into an executable HTML document: ```html <div class="render-root"> <!-- Rendered card nodes injected by renderer --> {{CARDS_HTML}} </div> ``` `references/browser-screenshot-spec.md:12-19` requires that the resulting document be loaded in a headless browser: ```markdown ## 2) Browser Context - Launch browser in headless mode. - Create context with: - `viewport = { width: viewport_width, height: viewport_height }` - `deviceScaleFactor = export_scale` - Keep default zoom (100%). - Do not use print/PDF rendering mode. ``` No corresponding requirement for HTML sanitization, JavaScript disabling, Content Security Policy enforcement, or browser request filtering is specified. ### Technical Analysis The skill instructs implementations to process attacker-controllable Markdown using the `md_in_html` extension and then inject rendered card HTML into a page opened by a headless browser. Raw HTML support can preserve active elements and attributes supplied through Markdown, depending on how the renderer constructs `CARDS_HTML`. Without a strict sanitization step, hostile input could contain constructs such as: - `<script>` elements. - Event-handler attributes such as `onerror` or `onload`. - `<iframe>`, `<object>`, or other embedded browsing contexts. - Remote images and other resource-loading elements. - Da ...[truncated 2324 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. **Sanitize all generated HTML** - Process Markdown output through a mature HTML sanitizer with a strict allowlist. - Permit only formatting elements required by the card renderer. - Remove `<script>`, `<iframe>`, `<object>`, `<embed>`, `<form>`, `<meta>`, `<link>`, and unneeded SVG/MathML content. - Remove all event-handler attributes, including attributes beginning with `on`. - Reject `javascript:`, `vbscript:`, and unsafe `data:` URLs. 2. **Disable raw HTML unless explicitly required** - Remove `md_in_html`. - Escape embedded HTML in Markdown by default. - If limited inline HTML is necessary, allow only explicitly documented, sanitized elements. 3. **Restrict browser network access** - Use Playwright request interception to deny all outbound requests by default. - Allow only resources that are necessary for rendering. - Block loopback, private, carrier-grade NAT, link-local, multicast, and metadata-service address ranges after DNS resolution. - Revalidate redirects and resolved addresses to prevent DNS rebinding and redirect-based bypasses. 4. **Harden the browser document** - Disable JavaScript if pagination and capture can operate without it; replace the font-readiness script with an implementation-side wait where feasible. - Otherwise, enforce a restrictive Content Security Policy such as `default-src 'none'`, with narrowly scoped exceptions for required local images and styles. - Use an isolated browser context without cookies, authentication state, extensions, or access to unrelated origins. - Keep the browser sandbox enabled and avoid unsafe launch flags such as `--no-sandbox`. 5. **Constrain resource consumption** - Add a maximum length for `markdown`, `title`, `author`, and `description`. - Enforce navigation, rendering, resource-download, and total-job timeouts. - Limit response sizes, image dimensions, DOM node counts, and concurrent rendering jobs. - ...[truncated 440 chars]
