T09 · Insecure Skill Coding Practices
- Location
scripts/report.py:378- Finding
Stored HTML and Script Injection Through Imported Campaign and Creative Names
- Content
View full analysis
{tier_name.replace('_', ' ')} {plan.get('name', '')} ¥{plan.get('budget', 0):,.0f} {plan.get('roas', 0)} ¥{plan.get('cpa', 0):.1f} {tier_data.get('rule', '')} """) ``` ```python # scripts/report.py:398-409 rows.append(f""" {rank_icon} {c.get('name', '')} ¥{c.get('cost', 0):,.0f} {c.get('ctr', 0)}% {c.get('cvr', 0)}% ¥{c.get('cpa', 0):.1f} {roas} {c.get('score', 0)}分 """) ``` ```python # scripts/report.py:423-434 rows.append(f""" {c.get('name', '')} {c.get('impressions', 0):,} {c.get('ctr', 0)}% {c.get('cvr', 0)}% ¥{c.get('cpa', 0):.1f} {c.get('roas', 0)} {c.get('active_days', 0)}天 {level} """) ``` ### Technical Analysis Campaign and creative names originate in user-supplied CSV, JSON, or ...[truncated 2311 chars]- Remediation
View remediation
{html_text(plan.get("name", ""))} ``` 2. Prefer a mature template engine such as Jinja2 with automatic escaping enabled rather than constructing the full report through Python f-strings. 3. Treat HTML text, HTML attributes, URLs, CSS, and JavaScript as separate output contexts. Do not reuse a generic sanitizer across these contexts. 4. Continue using JSON serialization for chart data, but also ensure that serialized content cannot terminate the enclosing script element. A safer design is to place serialized data in an `application/json` element and parse its text content. 5. Add a restrictive Content Security Policy that blocks inline and unexpected remote scripts. CSP should be defense in depth rather than a replacement for output encoding. 6. Add regression tests using payloads containing: - `` sequences - Encoded and mixed-case variants 7. Escape generated recommendation messages as well, because `scripts/optimizer.py` includes creative names in recommendation strings that are later inserted into report markup. ]]>
