T09 · Insecure Skill Coding Practices
- Location
scripts/generate_dashboard.py:396- Finding
Stored Cross-Site Scripting in Generated Dashboards
- Content
View full analysis
{title} ``` ```html📊 {title}
🌓 Toggle Theme ``` ```javascript grid.innerHTML = stats.map(s => ``).join(''); ``` ```javascript card.innerHTML = `${s.label}${s.value}${c.title}
`; ``` ```javascript let html = '' + TABLE_HEADERS.map(h => `${h}`).join('') + ''; html += '' + TABLE_ROWS.map(r => '' + TABLE_HEADERS.map(h => `${r[h] || ''}`).join('') + '' ).join('') + ''; table.innerHTML = html; ``` ```python chart_data_js = json.dumps({'charts': chart_data_list, 'stats': stats}, ensure_ascii=False) headers_js = json.dumps(headers, ensure_ascii=False) table_rows_js = json.dumps(table_rows, ensure_ascii=False) html = HTML_TEMPLATE.format( title=title, chart_data=chart_data_js, headers=headers_js, table_rows=table_rows_js ) ``` ### Technical Analysis CSV and JSON headers, cell values, chart titles derived from headers, and the command-line `--title` value can all contain attacker-controlled text. These values are embedded in the generated dashboard without context-appropriate encoding. There are two distinct injection mechanisms: 1. The dashboard title is inserted directly into the HTML `` and `<h1>` contexts through `str.format()` without HTML escaping. 2. Headers, raw table values, statistics labels, and chart titles are passed to JavaScript and subsequently rendered through `innerHTML`. Although `json ...[truncated 2064 chars]- Remediation
View remediation
` and `` contexts. 3. Safely embed serialized JSON. At minimum, encode characters that are significant to HTML parsing: ```python def safe_json_for_html(value): return ( json.dumps(value, ensure_ascii=False) .replace('&', r'\u0026') .replace('<', r'\u003c') .replace('>', r'\u003e') .replace('\u2028', r'\u2028') .replace('\u2029', r'\u2029') ) ``` A stronger design is to place JSON in a non-executable element such as `` sequences. - Encoded and mixed-case variants. 6. Treat every input dataset as untrusted, even when the dashboard is intended for local use. ]]>
