T09 · Insecure Skill Coding Practices
- Location
scripts/waimai_compare.py:242- Finding
Stored HTML and JavaScript Injection in Generated Reports
- Content
View full analysis
' + format_price(original_price) + '' ``` Attacker-influenced platform names are also serialized directly into an inline script: ```python radar_js_parts = [ "const platforms = " + json.dumps(radar_platforms, ensure_ascii=False) + ";", "const dimensions = " + json.dumps(radar_dimensions, ensure_ascii=False) + ";", "const scores = " + json.dumps(radar_scores, ensure_ascii=False) + ";", "const platformColors = " + json.dumps(radar_platform_colors, ensure_ascii=False) + ";", ] ``` ```python '', ``` ### Technical Analysis The report generator accepts structured JSON through `--data` or `--data-file`. Some textual fields are escaped with `html.escape`, but price values, coupon amounts, and coupon thresholds are returned without HTML encoding before being concatenated into the report. The inline JavaS ...[truncated 2198 chars]- Remediation
View remediation
`, `&`, U+2028, and U+2029 before insertion into HTML. 4. If inline JSON remains necessary, replace HTML-significant characters after serialization, for example by encoding `<` as `\u003c`, `>` as `\u003e`, and `&` as `\u0026`. 5. Add a restrictive Content Security Policy. Remove inline scripts where possible and disallow script execution from unapproved sources. 6. Add regression tests using payloads containing HTML elements, event handlers, quotes, ``, U+2028, and U+2029. ]]>
