T09 · Insecure Skill Coding Practices
- Location
src/index.js:207- Finding
Stored HTML Injection in Generated Reports
- Content
View full analysis
Vulnerability Details
File Location:
src/index.js, lines 207–221
Vulnerability Type: Stored HTML injection / cross-site scripting
Risk Level: MediumVulnerable Code
js export function renderHtmlReport(report, title = 'Skill Profiler Report') { const rows = report.profile.skills .map((s) => `<tr><td>${s.skill}</td><td>${s.runs}</td><td>${s.avgLatencyMs}</td><td>${s.p95LatencyMs}</td><td>${s.avgCpuMs}</td><td>${s.peakMemoryMb}</td></tr>`) .join(''); return `<!doctype html> <html><head><meta charset="utf-8"/><title>${title}</title> <style>body{font-family:Arial,sans-serif;padding:16px}table{border-collapse:collapse;width:100%}th,td{border:1px solid #ddd;padding:8px;text-align:left}</style> </head><body> <h1>${title}</h1> <p>Total runs: ${report.profile.totalRuns} | Sessions: ${report.profile.sessions} | P95 latency: ${report.profile.p95LatencyMs}ms</p> <h2>Bottlenecks (${report.analysis.bottlenecks.length})</h2> <ul>${report.analysis.bottlenecks.map((b) => `<li>${b.skill}: ${b.reasons.join(', ')}</li>`).join('')}</ul> <h2>Skill metrics</h2> <table><thead><tr><th>Skill</th><th>Runs</th><th>Avg Latency</th><th>P95 Latency</th><th>Avg CPU</th><th>Peak Memory</th></tr></thead><tbody>${rows}</tbody></table> </body></html>`; }Technical Analysis
The HTML report renderer directly interpolates dynamic values into HTML without context-appropriate encoding. In particular,
s.skillandb.skilloriginate from theskillproperty of records in the input JSON file. The exported function also accepts a caller-controlledtitle.An attacker can supply a skill name containing HTML or JavaScript, such as:
json { "sessionId": "malicious", "skill": "</td></tr><script>/* attacker code */</script><tr><td>", "latencyMs": 2000, "cpuMs": 1200, "memoryMb": 600 }Because metacharacters such as
<,>,&, quotes, and apostrophes are not escaped, th ...[truncated 1600 chars]- Remediation
View remediation
Remediation Suggestions
-
Apply HTML text-context escaping to every dynamic value before interpolation, including skill names, report titles, and bottleneck reason text. At minimum, encode:
&as&<as<>as>"as"'as'
-
Prefer a maintained escaping package or a templating system that enables automatic escaping by default rather than constructing HTML through raw template literals.
-
If retaining the current renderer, introduce a centralized helper and use it consistently:
js function escapeHtml(value) { return String(value) .replaceAll('&', '&') .replaceAll('<', '<') .replaceAll('>', '>') .replaceAll('"', '"') .replaceAll("'", '''); } -
Add a restrictive Content Security Policy to generated reports as defense in depth, for example disallowing scripts and remote resources:
html <meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; img-src data:"> -
Add regression tests that generate reports containing payloads such as
<script>, event-handler attributes, closing tags, ampersands, and quotes. Tests should verify that the original payload does not appear as active markup and that all metacharacters are encoded. -
Document that imported sample files are untrusted data and ensure future output formats use context-specific encoding rather than relying solely on input validation.
-
