T09 · Insecure Skill Coding Practices
- Location
score.py:56- Finding
Unescaped Metrics Data Allows HTML and Script Injection in Generated Reports
- Content
View full analysis
{t["failed"]}失败' tests_html += f""" {t.get('id','')} {t.get('name','')} {dur}s {tokens//1000}k {tools} {status_text}{extra} """ ``` Other unescaped values are interpolated into the report in the system and model sections: ```python{datetime.now().strftime('%Y-%m-%d %H:%M')} · {sys_info.get('os','')} · {sys_info.get('arch','')}``` ```pythonModel{model_info.get('name','—')}Context Window{model_info.get('context_window','—')}``` ```pythonOpenClaw{sys_info.get('openclaw_version','—')}Node.js{sys_info.get('node_version','—')}``` ### Technical Analysis The scorer reads metrics from a JSON file supplied through the command line: ```python with open(sys.argv[1]) as f: metrics = json.load(f) ``` Multiple string values from that JSON object are then inserted directly into an HTML document using Python f-strings. No HTML escaping, sanitization, schema validation ...[truncated 2307 chars]- Remediation
View remediation
{test_id} {test_name} {dur}s {tokens // 1000}k {tools} {status_text}{failed} """ ``` 2. Escape all system and model metadata, including OS, architecture, version, provider, model name, and context-window values. 3. Prefer an HTML template engine with automatic escaping enabled rather than constructing the document through large f-strings. 4. Validate the metrics JSON against a strict schema: - Require numeric types for durations, token counts, ratios, and tool counts. - Restrict status values to an explicit allowlist such as `ok` and `failed`. - Set reasonable maximum lengths for all display strings. - Reject unexpected nested objects and arrays where scalar values are expected. 5. Add a restrictive Content Security Policy to reduce the effect of any missed escaping: ```html ``` If external resources are not required, do not permit scripts, remote images, frames, forms, or network connections. 6. Add regression tests using payloads containing characters and elements such as `<`, `>`, `"`, `'`, `
