T09 · Insecure Skill Coding Practices
- Location
scripts/generate_report.py:455- Finding
Unescaped Ranking Data Enables HTML and Script Injection in Generated Reports
- Content
View full analysis
{rank} {account_name} {category} {score} {followers} {new_fans} {new_likes} {new_comments} {new_shares} """ ROW_TEMPLATE = """ {rank} {account_name} {score} {followers} {new_fans} {new_likes} {new_comments} {new_shares} """ ``` ```python account_name = item.get('accountName', '') profile_url = item.get('profileUrl', '') # ... if is_all_category: account_category = item.get('category', '-') rows.append(ROW_TEMPLATE_CAT.format( rank_class=rank_class, rank=rank, account_name=account_name, profile_url=profile_url or '#', category=account_category, score=score, followers=followers, new_fans=new_fans, new_likes=new_likes, new_comments=new_comments, new_shares=new_shares, )) else: rows.append(ROW_TEMPLATE.format( rank_class=rank_class, rank=rank, account_name=account_name, profile_url=p ...[truncated 3680 chars]- Remediation
View remediation
str: try: parsed = urlparse(value) if parsed.scheme == "https" and parsed.hostname == "www.douyin.com": return escape(value, quote=True) except Exception: pass return "#" ``` 3. Reject `javascript:`, `data:`, `file:`, and other unexpected schemes. Host validation must occur after parsing rather than through prefix matching. 4. Prefer a template engine with auto-escaping enabled instead of assembling HTML through unrestricted `str.format()` calls. 5. Add a restrictive Content Security Policy, for example one that denies inline scripts and limits network connections to the minimum required origins. 6. Remove automatic report opening or place it behind an explicit `--open` option. Report generation should not render externally controlled content without user confirmation. 7. Add regression tests containing account names such as ``, quotes, event handlers, and malformed URLs to confirm that they are rendered as text rather than executable markup. ]]>
