T09 · Insecure Skill Coding Practices
- Location
generate_mindmap.py:1271- Finding
Untrusted Mind-Map Content Can Inject JavaScript into Generated HTML
- Content
View full analysis
__TITLE__ ``` ```html🧠 __TITLE__
``` Untrusted title and tree data are also inserted into an executable script element: ```html- Remediation
View remediation
SAFE_JSON ``` ```javascript const RAW = JSON.parse(document.getElementById("mindmap-data").textContent); ``` 3. Even in an `application/json` element, escape characters significant to the HTML parser. At minimum, encode: - `<` as `\u003c` - `>` as `\u003e` - `&` as `\u0026` - U+2028 as `\u2028` - U+2029 as `\u2029` 4. Apply context-specific HTML escaping to title substitutions used in `` and `<h1>`, such as `html.escape(title, quote=True)`. 5. Avoid applying one placeholder replacement to both HTML and JavaScript contexts. Use separate, context-aware placeholders. 6. Add regression tests containing: - `</script>` - `<img src=x onerror=...>` - Quotes and backslashes - U+2028 and U+2029 - Nested malicious labels in both Markdown and JSON 7. Add a restrictive Content Security Policy. Refactor inline scripts and inline event handlers so that `script-src` does not require `unsafe-inline`. 8. Do not launch Chromium with `--no-sandbox` unless execution occurs inside a separately enforced operating-system sandbox or container. 9. If untrusted input must be rendered through Playwright, disable unnecessary browser capabilities and block outbound network requests during rendering. ]]>
