T09 · Insecure Skill Coding Practices
- Location
index.js:308- Finding
Persistent HTML and Script Injection in Generated Pages
- Content
View full analysis
${title} ``` ```html${title}
``` ```javascript if (line.startsWith('# ')) { if (currentSection) html += ''; const title = line.replace(/^#\s+/, ''); html += ` '; const title = line.replace(/^##\s+/, ''); html += `${title}
`; currentSection = 'main'; } else if (line.startsWith('## ')) { if (currentSection) html += '${title}
`; currentSection = 'sub'; } else if (line.trim()) { if (line.includes('$$')) { html += `${line.replace(/\$\$/g, '')}`; } else if (line.match(/^\[动画:/)) { html += this.renderAnimationBox(line); } else { html += `${line}
`; } } ``` ### Technical Analysis The generator treats lesson-file content as trusted markup. Document titles, headings, formulas, and ordinary lines are interpolated directly into the generated HTML without HTML escaping or sanitization. Because these values are placed in HTML element contexts, an attacker can inject closing tags, arbitrary HTML elements, inline event handlers, or script-capable content. For example, a lesson line containing: ```html``` is emitted inside a paragraph as active HTML rather than displayed as text. The same issue affects the document title and heading fields, where closing the existing element permits injection into the surrounding document. This is a persistent injection vulnerability because the payload is copied into the generated HTML file and remains active whenever that file is subsequently opened. ### Attack Path 1. An attacker creates or modifies a Markdown lesson file accepted by the generator. 2. Th ...[truncated 1295 chars]
- Remediation
View remediation
`, `"`, and `'` according to the output context. 2. Replace the custom line-based conversion with a maintained Markdown parser configured to disable or escape raw HTML. 3. Sanitize rendered Markdown with an allowlist-based HTML sanitizer before inserting it into the final document. 4. Do not permit event-handler attributes, script elements, dangerous URL schemes, embedded frames, or active SVG content. 5. Remove inline event handlers from generated markup so that a restrictive Content Security Policy can be applied. 6. Add a restrictive Content Security Policy that blocks inline scripts and limits scripts, connections, frames, objects, and base URLs to explicitly approved sources. 7. Add automated security tests using payloads in every supported content context, including headings, paragraphs, formulas, titles, malformed tags, event handlers, SVG payloads, and encoded variants. ]]>
