T09 · Insecure Skill Coding Practices
- Location
scripts/generate_report.py:371- Finding
Stored HTML and JavaScript Injection in Generated Reports
- Content
View full analysis
{dim['name']}{dim['desc']}{bar}{dim['score']}''') return '\n'.join(items) def build_analysis_cards(analyses): type_map = { 'demand': ('demand', '📊'), 'competition': ('competition', '🏪'), 'profit': ('profit', '💰'), 'seasonality': ('seasonality', '📅'), 'risk': ('risk', '⚠️'), 'opportunity': ('opportunity', '💡'), } cards = [] for a in analyses: css_class, icon = type_map.get(a.get('type', ''), ('', '📌')) content = a.get('content', '') if isinstance(content, list): content = '- ' + ''.join(f'
- {item} ' for item in content) + '
{content}
' cards.append(f'''''') return '\n'.join(cards) def build_action_items(actions): items = [] for a in actions: priority = a.get('priority', 'P2').lower() items.append(f'''{icon} {a['title']}
{content}''') return '\n' ...[truncated 4157 chars]{a.get('priority', 'P2')}{a['title']}
{a['desc']}
- Remediation
View remediation
` elements Numeric values used in scores or CSS widths must be validated as numbers rather than escaped as arbitrary strings. 3. **Safely serialize chart data.** Avoid embedding attacker-controlled strings directly into an executable inline script. Prefer placing JSON in a non-executable element: ```html ``` Before embedding, serialize it with an HTML-safe JSON encoder that escapes `<`, `>`, `&`, U+2028, and U+2029. Parse the value using `JSON.parse()` from trusted static JavaScript. 4. **Strengthen schema validation.** Validate that: - Text fields are strings and have reasonable maximum lengths. - `dimensions`, `analyses`, and `actions` are lists with bounded sizes. - Every dimension score is numeric and between 0 and 100. - Analysis types and priorities are selected from explicit allowlists. - Unexpected nested objects or HTML-capable values are rejected. 5. **Add a restrictive Content Security Policy.** Refactor the inline script into a separate trusted JavaScript file, then use a policy similar to: ```http Content-Security-Policy: default-src 'none'; script-src 'self' https://cdn.jsdelivr.net; style-src 'self'; img-src 'self' data:; connect-src 'none'; base-uri 'none'; object-src 'none' ``` ...[truncated 551 chars]
