T09 · Insecure Skill Coding Practices
- Location
scripts/build_graph.py:379- Finding
Stored Cross-Site Scripting in Generated Graph HTML
- Content
View full analysis
{name}' for name, c in cats_seen[:12] ) ``` The generated values are inserted directly into HTML and an executable script block: ```html __TITLE__ ``` ```html``` ```javascript const GRAPH=__GRAPH_JSON__; ``` Graph-controlled values are subsequently concatenated into an `innerHTML` assignment: ```javascript document.getElementById('sidebar-content').innerHTML='🌐 __TITLE__
Loading...
'+(n.layer||'?')+' · '+(n.isFramework?'🔑 Framework':'📄 Entry')+'Category: '+(n.category||'—')+''+(n.date?'Date: '+n.date+'':'')+''+n.label+'
'+(n.insight?''+n.insight+'':'')+(n.summary&&n.summary!==n.label?''+n.summary+'':'')+'Connections ('+conns.length+')'+(connHtml||''; ``` The final substitutions do not apply context-aware encoding: ```python html = (html_template .replace("__TITLE__", title) .replace("__LEGEND__", legend_items) ...[truncated 2735 chars]No connections')+'- Remediation
View remediation
`, `&`, U+2028, and U+2029 in serialized JSON before placing it in a script element; or - Store JSON in a non-executable element and parse its `textContent`; or - Load the graph from a separate JSON resource served with the correct content type. 4. Apply `html.escape(value, quote=True)` to title and legend text before inserting them into HTML. 5. Validate color values against a strict allowlist, such as hexadecimal RGB/RGBA values, rather than inserting arbitrary configuration strings into style attributes. 6. Consider adding a restrictive Content Security Policy that disallows inline scripts. This should be defense in depth and not a replacement for output encoding. 7. Add regression tests with payloads in every source field, including: - `` - `` - Attribute-breaking strings - Malicious category colors and manual-link labels 8. Regenerate any previously published graph after removing malicious or untrusted content. ]]>
