T09 · Insecure Skill Coding Practices
- Location
SKILL.md:71- Finding
Unsanitized Markdown and HTML Content in Generated Output
- Content
View full analysis
\u7b2c\u4e00\u884c\u4ee3\u7801
\u7b2c\u4e8c\u884c\u4ee3\u7801
``` ```html``` The workflow further requires the converter to preserve existing `
` code blocks as HTML and replace local image paths with CDN URLs, but it does not require sanitization, escaping, URL validation, or an HTML allowlist. ### Technical Analysis The Skill directs an agent to interpolate Markdown-derived content into HTML elements and preserve existing ` ` blocks. No instruction requires HTML metacharacters such as `&`, `<`, `>`, `"`, and `'` to be escaped before untrusted text is inserted into generated markup. Consequently, content intended to be displayed as text or code may instead be interpreted as active HTML. For example, attacker-controlled Markdown could contain an image element with an event handler, a deceptive form, an iframe, or another browser-supported element. Preserving an existing ` ` block without sanitization also allows embedded child elements and attributes to survive conversion. The image conversion rule introduces an additional injection surface because `sr ...[truncated 2259 chars] - Remediation
View remediation
` in text nodes. - Escape `&`, `<`, `>`, `"`, and `'` in attribute values. - Treat code-block contents strictly as text, even when they contain HTML-like syntax. 2. Do not preserve arbitrary existing `` blocks. Parse and sanitize them using a strict allowlist containing only the elements and attributes required for the output format. 3. Remove all event-handler attributes, including attributes beginning with `on`, and reject active or embedding elements such as `script`, `iframe`, `object`, `embed`, `form`, and `meta`. 4. Validate image URLs before placing them into `src`: - Permit only `https` URLs. - Restrict hosts to explicitly approved CDN domains. - Reject `javascript:`, `data:`, `file:`, and other unapproved schemes. - Normalize and parse URLs with a URL parser rather than string matching. 5. Distinguish trusted converter-generated markup from user-controlled source content. Only markup generated from fixed templates should bypass sanitization. 6. Add adversarial conversion tests covering: - Closing-tag injection. - Quoted and unquoted attribute injection. - Event-handler attributes. - Script and iframe elements. - Malicious URL schemes. - HTML embedded in inline and fenced code. - Raw ` ` elements containing unsafe descendants. 7. Sanitize the completed output as a final defense-in-depth step before writing the `*_for_paste.html` file. ]]>
