T09 · Insecure Skill Coding Practices
- Location
scripts/report.py:408- Finding
Stored HTML Injection in Generated Comment Reports
- Content
View full analysis
{i+1}{a["name"]}{a["count"]} 条评论' for i, a in enumerate(top_authors))} ... {"".join(f'' for c in comments[:50])} ``` ### Technical Analysis The report generator interpolates author names and comment content directly into an HTML document without HTML escaping or contextual output encoding. These values originate from externally controlled Douyin comments and account profile names. Truncating comment content to 200 characters does not prevent injection because a functional HTML or event-handler payload can fit within that limit. For example, a crafted author name or comment containing an image element with an error event handler would be interpreted as markup rather than displayed as text. The generated report also has no restrictive Content Security Policy to mitigate inline event handlers or injected scripts. ### Attack Path 1. An attacker posts a crafted comment or uses a crafted account display name on a video managed by the victim. 2. `scripts/fetch_comments.py` collects the attacker-controlled value and writes it to the comment JSON data. 3. The user runs `scripts/report.py` with that JSON file. 4. `generate_html_report()` inserts the malicious value directly into `report.html`. 5. The user opens the generated report in a browser. 6. The browser parses the attacker-controlle ...[truncated 705 chars]{c.get("author_name", "?")[0] if c.get("author_name") else "?"}{c.get("author_name", "匿名用户")}{c.get("content", "")[:200]}👍 {c.get("like_count", 0)} · {c.get("create_time", "")[:10]}- Remediation
View remediation
``` - Treat all imported JSON data as untrusted, even when it was produced by another script in the project. - Add regression tests containing HTML elements, quotes, event handlers, and closing tags, then verify that the resulting report displays them only as text. ]]>
