T09 · Insecure Skill Coding Practices
- Location
scripts/cross_border_tax.py:1007- Finding
HTML Injection in Generated Report Title
- Content
View full analysis
Vulnerability Details
File Location:
scripts/cross_border_tax.py, lines 1007 and 1064; input and output flow at lines 1166 and 1207–1210
Vulnerability Type: Unescaped user input in generated HTML
Risk Level: MediumVulnerable Code
python query = result.get("query", "") title = f"跨境税务速查 · {query[:30]}" if not query: title = "跨境多国税务速查报告"html <title>{title}</title>The relevant input and output flow is:
python query = sys.argv[1] # Parse query result = parse_query(query) result["query"] = query # Generate HTML html = build_html(result) safe_name = re.sub(r'[^\w\-]', '_', query)[:40] or "tax_report" output_path = os.path.join(output_dir, f"{safe_name}.html") with open(output_path, "w", encoding="utf-8") as f: f.write(html)Technical Analysis
The command-line query is attacker-controlled and is copied into the HTML document's
<title>element without context-appropriate escaping. The filename sanitization only affectsoutput_path; it does not sanitize the HTML content.An input containing a closing
</title>sequence can terminate the title element and inject additional HTML markup. Browser-executable markup may consequently run when a user opens the generated report. The 30-character truncation reduces payload length but does not prevent injection because short breakout payloads and externally referenced browser behaviors may still fit within that limit.The generated reports do not define a Content Security Policy that would otherwise limit injected active content.
Attack Path
- An attacker supplies, or persuades a user or Agent to submit, a crafted tax query containing HTML metacharacters and a
</title>breakout sequence. main()reads the query fromsys.argv[1].- The query is stored in
result["query"]and passed tobuild_html(). build_html()interpolates the first 30 characters directly intotitle.- The value is inserted verbatim into the document's
<title>el ...[truncated 816 chars]
- An attacker supplies, or persuades a user or Agent to submit, a crafted tax query containing HTML metacharacters and a
- Remediation
View remediation
Remediation Suggestions
- Escape the query before placing it into HTML:
python import html query = result.get("query", "") safe_query = html.escape(query[:30], quote=True) title = f"Cross-Border Tax Quick Lookup · {safe_query}"-
Prefer a templating engine with automatic HTML escaping rather than constructing documents through unrestricted f-string interpolation.
-
Apply context-specific escaping to every dynamic value inserted into HTML, including future database content or user-provided fields. Filename sanitization must remain separate from HTML escaping.
-
Add a restrictive Content Security Policy, such as:
html <meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; img-src 'self' data:">Adjust the policy only for resources that the report legitimately requires.
- Add regression tests using inputs containing characters and sequences such as:
text </title> <script> <img onerror=...> & < "The tests should confirm that these values appear only as encoded text and cannot create new DOM elements or event handlers.
