T09 · Insecure Skill Coding Practices
- Location
assets/report_template.html:297- Finding
Unescaped HTML Template Substitution Allows Script Injection
- Content
View full analysis
{{PLAN_TITLE}} ``` ```html``` It also inserts complete generated HTML fragments without an established sanitization boundary: ```html {{PHASE_DETAILS}} ``` ```html{{STAGE_BADGE}}{{PLAN_TITLE}}
📅 {{DATE_RANGE}} ⏱ {{TOTAL_DAYS}} days 📋 {{SUBJECT}}{{MILESTONE_CARDS}}``` ```html {{CHECKPOINT_ROWS}} ``` ```html{{TIPS_ITEMS}}``` The generation instructions define task, milestone, checkpoint, and tip fields as direct substitutions into HTML elements: ```html{{TASK_CONTENT}}``` ```html``` ### Technical Analysis The skill instructs the agent to collect user-supplied study information, preserve user subject wording, generate additional textual fields, and replace template placeholders with those values. No contextual HTML escaping, allowlist sanitization, or input validation require ...[truncated 2682 chars]{{MS_ICON}}{{MS_TITLE}}{{MS_DESC}}📅 {{MS_DATE}} 📊 {{MS_METRIC}} {{MS_PRIORITY_LABEL}}- Remediation
View remediation
`, `"`, and `'`. - Use separate encoding rules for HTML text, attributes, URLs, CSS values, and JavaScript contexts. 2. **Use an auto-escaping template engine** - Replace unrestricted string substitution with a template engine that escapes values by default. - Reserve raw-HTML output operations for static, developer-controlled fragments only. 3. **Construct repeated sections safely** - Represent phases, tasks, milestones, checkpoints, and tips as structured data. - Generate nodes through safe DOM APIs and assign user-derived values through `textContent`. - If server-side generation is required, escape each nested textual field before assembling the fragment. 4. **Sanitize any intentionally supported HTML** - If formatting markup must be accepted, process it with a maintained HTML sanitizer configured with a strict allowlist. - Reject scripts, event-handler attributes, inline frames, embedded objects, dangerous URL schemes, and active SVG or MathML content. - Do not rely on pattern matching or simple tag removal as a sanitizer. 5. **Validate structural template fields** - Restrict `PRIORITY_CLASS`, `PHASE_CLASS`, numeric percentages, dates, and similar structural values to explicit allowlists or validated formats. - Do not allow arbitrary user-controlled strings in class names, style attributes, or other structural contexts. 6. **Harden report rendering** - Add a restrictive Content Security Policy that blocks inline scripts and event handlers. - Move legitimate interaction code to a fixed local script and authorize it with a hash or nonce where appropriate. - Present generated reports in a sandboxed frame without unnecessary same-origin or privileged capabilities. 7. **Add security regression tests** - Test every user-derived fie ...[truncated 301 chars]
