T09 · Insecure Skill Coding Practices
- Location
assets/report-template.html:404- Finding
Stored HTML and Script Injection in Generated Reports
- Content
View full analysis
` 之前插入数据脚本标签:`` 4. 用当前日期替换模板中的 `{{REPORT_DATE}}` 和 `{{OVERALL_SCORE}}` 占位符 5. 将最终 HTML 写入工作目录,文件命名:`人生轮盘报告-YYYY-MM-DD.html` 6. 使用 `present_files` 展示报告 ``` Reflection values are interpolated into HTML and assigned through `innerHTML`: ```javascript const container = document.getElementById('reflections'); container.innerHTML = reflections.map((r, i) => ``).join(''); ``` History values are also interpolated into HTML without output encoding: ```javascript const table = document.getElementById('historyTable'); const header = `时间${DIMENSIONS.map(d => `${d.short}`).join('')}均分`; const rows = [...history].reverse().map((h, idx, arr) => { const prev = arr[idx + 1]; const avg = (DIMENSIONS.reduce((s, d) => s + h[d.id], 0) / 8).toFixed(2); return ` ${h.date || ''} ${DIMENSIONS.map(d => { const cur = h[d.id]; if (!prev) return `${cur}`; const diff = cur - prev[d.id]; if (diff > 0) return `${cur} ↑${diff}`; if (diff < 0) return `${cur} ↓${Math.abs(diff)}`; return `${cur}`; }).join('')} ${avg} `; }).join(''); table.innerHTML = header + rows; ``` ### Technical Analysis The report renderer treats reflection and history data as trusted ma ...[truncated 2440 chars]Q${i+1}: ${questions[i] || ''}${r}- Remediation
View remediation
`, `&`, U+2028, and U+2029. - Prefer loading data from a separately generated JSON file where the runtime environment permits it. 4. If rich text is intentionally supported, sanitize it with a well-maintained allowlist-based HTML sanitizer. Do not implement sanitization with regular expressions. 5. Add a restrictive Content Security Policy. For a fully local report, disallow network access and inline script execution where practical. 6. Treat data read from `localStorage` as untrusted. Validate and safely render it each time it is loaded. 7. Add regression tests using payloads containing HTML elements, event handlers, quotes, and script-closing sequences to verify that they are displayed as text rather than interpreted as markup. ]]>
