T09 · Insecure Skill Coding Practices
- Location
references/report-template.md:34- Finding
Unescaped User-Controlled Content in Generated HTML Report
- Content
View full analysis
{{summary}}① 目标清晰度{{s1}}/20{{e1}}② 身体与基础状态{{s2}}/20{{e2}}③ 饮食管理能力{{s3}}/20{{e3}}④ 运动与塑形能力{{s4}}/20{{e4}}⑤ 生活方式与执行力{{s5}}/20{{e5}}接下来最重要的 3 件事
① {{t1}}② {{t2}}③ {{t3}}教练寄语 {{coach}}``` The corresponding instructions require these placeholders to be replaced with assessment-derived content, but do not require HTML escaping or sanitization: ```text Replace {{placeholders}} with real content. ` ...[truncated 3190 chars]- Remediation
View remediation
` to `>` - `"` to `"` - `'` to `'` 2. **Treat assessment-derived content as plain text.** Do not preserve HTML supplied by users in `summary`, dimension explanations, tasks, or the coach message. 3. **Use context-specific validation.** - Scores must be integers from `0` through `20`. - Percentages must be numeric values from `0` through `100`. - SVG coordinates must match a strict numeric-coordinate format and should be calculated internally. - Do not place arbitrary user-controlled strings into style, SVG, or other attribute contexts. 4. **Avoid direct string-based HTML construction where possible.** Build the report through a trusted HTML templating system with automatic escaping, or assign dynamic values through DOM `textContent` rather than `innerHTML`. 5. **Sanitize any intentionally supported formatting.** If limited markup such as highlighting must be permitted, generate that markup internally. Otherwise, process content with an allowlist-based HTML sanitizer that rejects scripts, event-handler attributes, unsafe URLs, embedded objects, and SVG active content. 6. **Add a restrictive Content Security Policy to the generated report**, for example: ```html ``` 7. **Add adversarial test cases** containing closing tags, event handlers, script elements, malformed attributes, SVG payloads, and encoded markup. Verify that each payload is rendered visibly as text and never interpreted as DOM content. ]]>
