T09 · Insecure Skill Coding Practices
- Location
skills/amazon-aba-kw-heat-report/scripts/generate_report.py:400- Finding
Stored Cross-Site Scripting in Generated ABA HTML Reports
- Content
View full analysis
' + i.label + '' + (i.value == null ? '—' : i.value) + '' + (i.sub ? '' + i.sub + '' : '') + ''; }).join(''); function buildSmallMultiples() { const grid = document.getElementById('smGrid'); grid.innerHTML = ''; const x = DATA.all_dates || []; DATA.chart_series.forEach(function(s, idx) { const m = metricByName(s.name) || {}; const tile = document.createElement('div'); tile.className = 'sm-tile' + (s.name === focusKw ? ' active' : ''); tile.dataset.kw = s.name; tile.innerHTML = '' + s.name + 'SFR ' + (m.latest_sfr == null ? '—' : m.latest_sfr) + ''; ``` ```javascript function renderTable() { const tb = document.querySelector('#metricsTable tbody'); tb.innerHTML = DATA.metrics_table.map(function(m) { const yoy = m.avg_yoy_change_pct; const yoyStr = (typeof yoy === 'number') ? ((yoy>0?'+':'') + yoy + '%') : yoy; const trClass = m.keyword === focusKw ? ' class="focus-row"' : ''; return '' + '' + m.keyword + '' + '' + tierLab ...[truncated 2745 chars]- Remediation
View remediation
``` Populate that element using a serializer that escapes at least `<`, `>`, `&`, U+2028, and U+2029, then parse its `textContent`. 3. Replace all `innerHTML` string construction with DOM APIs: - Use `document.createElement()`. - Assign untrusted values through `textContent`. - Use `setAttribute()` only after validating the value. 4. Validate color fields against a strict allowlist, such as six-digit hexadecimal colors generated internally by the report. 5. Treat keywords, trend labels, dates, and all remote ABA response fields as untrusted. 6. Add regression tests using payloads that contain: - Closing script tags. - Image elements with error handlers. - Quotes that escape `data-kw`. - Malicious CSS attribute values. 7. Deploy a restrictive Content Security Policy as defense in depth, avoiding `unsafe-inline` scripts where possible. ]]>
