T09 · Insecure Skill Coding Practices
- Location
scripts/report_generator.py:32- Finding
Stored HTML and JavaScript Injection in Generated Reports
- Content
View full analysis
= 75 else ("#f59e0b" if p.get("overall_score", 0) >= 60 else "#ef4444") product_cards += f"""""" ``` The same insecure interpolation pattern also appears in profit advice, location details, weather tips, competitor information, checklist entries, user-profile fields, and final recommendations throughout lines 71-320. ### Technical Analysis The report generator accepts externally supplied JSON through the `--data` or `--data-file` arguments. String values from this JSON are inserted directly into an HTML document using ...[truncated 2211 chars]#{i+1}{p.get('category_icon', '📦')} {p.get('name', '未知品类')}{p.get('category', '')} {p.get('difficulty_label', '')} 竞争: {p.get('competition', '未知')}¥{p.get('min_budget', 0)}+启动金{p.get('profit_rate', 0)*100:.0f}%毛利率¥{p.get('daily_range', '')}日流水{p.get('overall_score', 0)}分- Remediation
View remediation
str: return escape(str(value), quote=True) ``` Use the helper consistently: ```python product_name = html_text(p.get("name", "Unknown product")) category = html_text(p.get("category", "")) ``` 2. Do not assume values produced by an Agent or loaded from a local JSON file are trusted. Treat every report field as untrusted input, including list entries and nested dictionaries. 3. Validate the complete input structure before rendering: - Require expected object and array types. - Enforce numeric types and reasonable ranges for scores, percentages, and monetary values. - Limit string lengths to prevent oversized reports and rendering abuse. - Reject unexpected fields where practical. 4. If selected fields intentionally support formatted content, sanitize them with a maintained HTML allowlist sanitizer. Permit only necessary tags and attributes, and reject scripts, event-handler attributes, unsafe URLs, embedded objects, and active SVG content. 5. Add a restrictive Content Security Policy, preferably through an HTTP response header when reports are served. For standalone files, include an appropriate policy in a `` element. Move the legitimate inline script to a separate trusted file or protect it with a nonce or hash. A baseline policy should deny plugins, frames, and uncontrolled network access. 6. Add regression tests using payloads in every string-bearing field, including: ```html"> ``` Tests should verify that these payloads appear as escaped text and never create executable DOM nodes. ]]>
