T09 · Insecure Skill Coding Practices
- Location
scripts/run_monitor.py:344- Finding
Stored HTML and Script Injection in Generated Patent Report
- Content
View full analysis
{pub_num}' else: pub_num_cell = pub_num rows_html += f""" {i} {pub_num_cell} {title} {assignee}- Remediation
View remediation
str: return html.escape(safe_str(value), quote=True) ``` Escape titles, assignees, publication numbers, dates, status values, summaries, branch names, keywords, company names, and all other data-derived strings. 2. **Strictly validate patent URLs.** Parse URLs with `urllib.parse.urlsplit()` and allow only explicitly approved schemes and, if feasible, approved PatSnap hostnames: ```python from urllib.parse import urlsplit def safe_patent_url(value: str) -> str: value = safe_str(value).strip() parsed = urlsplit(value) if parsed.scheme != "https": return "" if parsed.hostname not in {"analytics.patsnap.com", "www.patsnap.com"}: return "" return html.escape(value, quote=True) ``` Reject `javascript:`, `data:`, `file:`, protocol-relative, malformed, and unexpected URLs. 3. **Harden external links.** Add opener isolation: ```html target="_blank" rel="noopener noreferrer" ``` 4. **Use an auto-escaping template engine.** Replace manual f-string HTML assembly with a template engine such as Jinja2 configured with automatic HTML escaping. Keep URL validation separate because HTML escaping alone does not make a dangerous URL scheme safe. 5. **Add a restrictive Content Security Policy.** Include a policy that blocks inline scripts, event handlers, plugins, and unexpected network destinations. For a self-contained report, a restrictive starting point is: ```html ``` Adjust only those directives demonstrably required by the repor ...[truncated 278 chars]
