T09 · Insecure Skill Coding Practices
- Location
scripts/vendor/generate_mindmap_clawhub.py:2382- Finding
Stored Script Injection in Generated Mind-Map HTML
- Content
View full analysis
` element. In particular, a string containing `` can terminate the surrounding script element because HTML parsing recognizes that sequence before JavaScript or JSON parsing occurs. The meeting wrapper derives the title and node labels from user-provided meeting topics and minutes. Consequently, malicious content can reach the vulnerable renderer and be persisted in the generated HTML file. ### Attack Path 1. An attacker supplies a crafted meeting topic or transcript containing a payload such as: ```html ``` 2. `scripts/generate_meeting_mindmap.py` extracts ...[truncated 1237 chars]- Remediation
View remediation
... ``` Parse it using: ```javascript const raw = JSON.parse(document.getElementById("mindmap-data").textContent); ``` 3. Before embedding JSON in HTML, neutralize characters significant to the HTML parser: ```python def safe_json_for_html(value): return ( json.dumps(value, ensure_ascii=False) .replace("&", "\\u0026") .replace("<", "\\u003c") .replace(">", "\\u003e") .replace("\u2028", "\\u2028") .replace("\u2029", "\\u2029") ) ``` 4. Avoid generic placeholder replacement for mixed HTML and JavaScript contexts. Use a template engine with automatic HTML escaping and an explicit safe-JSON helper. 5. Add a restrictive Content Security Policy to generated HTML, avoiding `unsafe-inline` where practical. 6. Add regression tests using titles and node labels containing: - `` - `` - Quotes and backslashes - Ampersands and angle brackets - U+2028 and U+2029 ]]>
