T09 · Insecure Skill Coding Practices
- Location
references/output-templates.md:484- Finding
Unescaped External Data and Unvalidated URLs in Generated HTML Reports
- Content
View full analysis
[来源1] — [内容] · 采集时间:[日期]
· [来源2] — [内容] · 采集时间:[日期]
``` At lines 626–632, externally derived source and descriptive data are placed directly into quoted HTML attributes: ```html``` ```html[X,XXX–X,XXX 元][区域说明]``` ### Technical Analysis The Skill obtains URLs, platform names, descriptions, and other report content from public search results and community sources. The HTML templates place these values into HTML text and quoted attribute contexts without requiring context-sensitive encoding or URL-scheme validation. A maliciously crafted value containing quotation marks and HTML markup could terminate a `data-tip` or `href` attribute and introduce additional attributes or elements. For example, an attacker-controlled description shaped like the following could create an event handler after template substitution: ```text " onmouseover="ATTACKER_CODE ``` Likewise, a source URL using a dangerous scheme such as `javascript:` could execute script when the user clicks the generated source link. The template does not require an allowlist restricting links to `https:` or `http:`. The included static animation script is not itself malicious. The vulnerability arises because generated reports are executable HTML documents and untrusted research data is not explicitly separated from their markup and script context. ### Attack Path 1. A ...[truncated 1383 chars][XXX–X,XXX 元]食堂+外卖估算- Remediation
View remediation
`, `"`, and `'`. - Apply attribute-specific encoding to values inserted into `data-tip`, `href`, and other attributes. 2. **Validate source URLs** - Parse each URL before adding it to the report. - Permit only explicitly approved schemes, normally `https:` and optionally `http:`. - Reject `javascript:`, `data:`, `file:`, `vbscript:`, and malformed URLs. - Resolve and validate redirected destinations where practical. 3. **Harden external links** - Add `target="_blank"` only when needed. - When opening a new browsing context, add: ```html rel="noopener noreferrer" ``` 4. **Avoid raw string interpolation** - Generate report elements through a safe DOM API and assign untrusted text through `textContent`. - Alternatively, use a template engine that performs context-aware auto-escaping by default. - Never construct HTML by concatenating raw search-result metadata. 5. **Sanitize permitted rich content** - If formatting from external sources must be preserved, process it with a maintained HTML sanitizer using a minimal element and attribute allowlist. - Do not permit event-handler attributes, script-capable elements, inline styles, or arbitrary URI-bearing attributes. 6. **Add explicit Skill instructions** - State that web content, community quotations, source labels, and URLs are untrusted. - Require escaping and validation before inserting any retrieved value into an HTML report. - Require plain-text rendering when safe sanitization cannot be guaranteed. 7. **Add regression tests** - Test source values containing quotation marks, angle brackets, event handlers, and encoded payloads. - Test links using mixed-case or encoded dangerous schemes. - Verify that payloads are displayed as inert text and that unsafe links are omitted. ]]>
