T09 · Insecure Skill Coding Practices
- Location
scripts/generate_reports.py:583- Finding
Stored HTML and JavaScript Injection in Generated Dashboard
- Content
View full analysis
- Remediation
View remediation
{ const row = tableBody.insertRow(); appendTextCell(row, index + 1); appendTextCell(row, product.asin); appendTextCell(row, product.title); appendTextCell(row, product.brand); appendTextCell(row, `$${product.price}`); appendTextCell(row, product.rating); appendTextCell(row, product.sales); appendTextCell(row, `${product.marketShare}%`); }); ``` 2. Store serialized data in a non-executable element: ```html ``` Parse it using: ```javascript const reportData = JSON.parse( document.getElementById('report-data').textContent ); ``` 3. Before embedding JSON in HTML, escape HTML-significant and script-sensitive characters. At minimum, transform `<`, `>`, `&`, U+2028, and U+2029 into Unicode escape sequences. This prevents literal `` sequences from appearing in the generated file. 4. Apply contextual HTML escaping to direct replacements such as category names, site names, ratings, and seller summaries. 5. Validate API response fields against a strict schema, including expected types and maximum lengths. 6. Add a restrictive Content Security Policy. Prefer a locally bundled script and avoid inline JavaScript so that `script-src 'self'` can be enforced without `unsafe-inline`. 7. Add regression tests using payloads containing ``, event-handler attributes, HTML entities, quotes, backticks, and Unicode line separators. ]]>
