T09 · Insecure Skill Coding Practices
- Location
scripts/score_test.py:640- Finding
Stored HTML Injection Through Unescaped Report Metadata
- Content
View full analysis
{result.model or "N/A"} | {result.test_mode.upper()} | {result.test_date}') ``` ### Technical Analysis The report generator directly interpolates `result.model`, `result.test_mode`, and `result.test_date` into an HTML document without HTML escaping. These values originate from report metadata and must therefore be treated as untrusted. Other parts of the same report generator use `html_mod.escape()`, but this output path omits that protection. An attacker who can supply or influence the assessment data can use a payload such as: ```html``` When assigned to `result.model`, the payload becomes executable markup in the generated report rather than displayed text. The generated report also lacks a restrictive Content Security Policy, so inline event handlers are not explicitly blocked. ### Attack Path 1. The attacker prepares assessment data containing malicious HTML in `model`, `test_mode`, or `test_date`. 2. The data is converted into a `TestResult` and passed to `generate_html_report()`. 3. The report generator inserts the malicious value directly into the HTML at line 640. 4. A user opens the generated report in a web browser. 5. The browser parses the injected markup and executes the attacker's JavaScript in the report's browsing context. Exploitation requires the attacker to control report metadata and persuade an operator to generate and open the resulting HTML report. ### Impact Assessment Successful exploitation allows arbitrary client-side script execution in the generated report's browsing context. Depending on how and where the report is hosted, the attacker may: - Alter assessment scores, comments, and other displa ...[truncated 505 chars]
- Remediation
View remediation
' f'{safe_model} | {safe_mode} | {safe_date}' ) ``` Additional hardening measures: 1. Validate `test_mode` against an explicit allowlist such as `{"quick", "standard", "full", "lli"}`. 2. Introduce a shared HTML-escaping helper and require it for every dynamic text field. 3. Prefer a template engine with automatic escaping rather than constructing HTML through string interpolation. 4. Add a restrictive Content Security Policy that blocks inline scripts and event handlers. 5. Add regression tests using payloads such as ``, attribute-breaking strings, and encoded markup. 6. Test all report metadata fields, not only comments and recommendation text. ]]>
