T09 · Insecure Skill Coding Practices
- Location
scripts/render_dashboard.py:357- Finding
Stored JavaScript Injection in the Generated Dashboard
- Content
View full analysis
str: return json.dumps(rows, ensure_ascii=False, separators=(",", ":")) ``` ```python rows_json = render_table_rows(clean_rows) ``` ```html- Remediation
View remediation
... ``` Then parse its `textContent`: ```javascript const rows = JSON.parse(document.getElementById("portfolio-data").textContent); ``` 3. Before embedding JSON in HTML, escape at least `<`, `>`, `&`, U+2028, and U+2029. For example: ```python def html_safe_json(value: Any) -> str: return ( json.dumps(value, ensure_ascii=False, separators=(",", ":")) .replace("&", "\\u0026") .replace("<", "\\u003c") .replace(">", "\\u003e") .replace("\u2028", "\\u2028") .replace("\u2029", "\\u2029") ) ``` 4. Replace `innerHTML` table generation with `document.createElement()`, `textContent`, and explicit attribute assignment. 5. Validate publisher handles and slugs against the exact ClawHub identifier grammar before constructing URLs. 6. Construct links with the `URL` API and allow only `https:` URLs targeting the expected ClawHub hostname. 7. Add regression tests using payloads containing ``, quotation marks, HTML tags, event handlers, and malformed slugs. 8. Consider a restrictive Content Security Policy that disallows inline scripts and limits outbound connections. ]]>
