T09 · Insecure Skill Coding Practices
- Location
scripts/report.py:367- Finding
Stored HTML and JavaScript Injection in Generated Reports
- Content
View full analysis
= 7 else 'warning' if d['total_score'] >= 5 else 'danger' status_map = {'pending': '待执行', 'executed': '已执行', 'cancelled': '已取消', 'reviewed': '已复盘'} decision_rows += f""" {d.get('name', d['symbol'])} {d['decision_type']} {d['total_score']} {status_map.get(d['status'], d['status'])} {d.get('decision_date', '')} """ ``` ```python for h in portfolio['holdings']: mv = h['quantity'] * (h['current_price'] or h['avg_cost']) cost = h['quantity'] * h['avg_cost'] pnl = mv - cost pnl_pct = (pnl / cost * 100) if cost > 0 else 0 pnl_c = 'pnl-positive' if pnl >= 0 else 'pnl-negative' holdings_rows += f""" {h['symbol']} {h.get('name', '')} {h['asset_class']} {h['quantity']} ¥{h['avg_cost']:.2f} ¥{mv:,.2f} {pnl:+,.2f} ({pnl_pct:+.1f}%) """ ``` ```python for w in watchlist: watchlist_rows += f""" {w['symbol']} {w.get('name', '')} {w.get('reason', '')} {f"¥{w['target_price']:.2f}" if w['target_price'] else '-'} """ ``` ```python{decision.get('outcome_notes', '')}``` ```python{decision.get(' ...[truncated 2367 chars]
- Remediation
View remediation
{html_text(d.get('name', d['symbol']))}{html_text(decision.get('thesis'), 'Not recorded')}
``` 3. Prefer a template engine configured with automatic HTML escaping rather than manually constructing documents with f-strings. 4. Keep numeric formatting separate from text escaping and validate that expected numeric fields are finite numbers. 5. Add a restrictive Content Security Policy to generated documents as defense in depth, for example by disallowing scripts and remote connections where interactivity does not require them. 6. Add regression tests covering `
