T09 · Insecure Skill Coding Practices
- Location
assets/report-template.html:199- Finding
Unescaped User-Controlled Values in Generated HTML Report
- Content
View full analysis
{{PRODUCT}}
{{MARKET}} — 出口合规报告``` The corresponding workflow identifies product category and destination market from user-controlled messages without defining output-encoding requirements: ```md - `category` — 产品品类,映射到上述 8 大品类之一 - `market` — 目的地市场,映射到上述 8 大市场之一 (或 GCC 中的具体国家) - `platform` (可选) — 平台名称 (如亚马逊/速卖通/Temu/Coupang),用于额外要求标注 ``` ### Technical Analysis The report template places dynamic values directly into HTML text and attribute contexts. The Skill does not require HTML escaping, sanitization, or strict allowlist validation before replacing these placeholders. In particular: - `PRODUCT`, `MARKET`, `GEN_DATE`, and `RISK_LEVEL` are inserted into HTML text contexts. - `RISK_CLASS` is inserted into an HTML attribute context. - Product and market information originates from the user's message. - The template contains active JavaScript and is intended to be opened as an interactive HTML document. If the report generator performs direct string replacement, characters such as `<`, `>`, `"`, `'`, and `&` can alter the document structure. An attacker could close the intended element and insert an event handler or another executable HTML construct. The vulnerability is contingent on dynamic values being copied into the template without contextual encoding, which the current Skill contract neither prevents nor detects. ### Attack Path 1. An attacker supplies a crafted product name or market value, for example: ```html{{GEN_DATE}}{{RISK_LEVEL}}``` 2. The Skill e ...[truncated 1421 chars]
- Remediation
View remediation
`, `"`, and `'`. - Apply attribute-specific encoding to values used inside attributes. 2. **Constrain values to fixed enumerations** - Map product categories and markets to internal identifiers and canonical display names. - Do not copy arbitrary user-provided text into the template when a fixed category or market name is available. - Allowlist `RISK_CLASS` to known values such as `risk-high`, `risk-medium`, and `risk-low`. 3. **Use safe DOM construction** - Populate dynamic fields with `textContent` rather than `innerHTML`. - Construct tables, cards, and checklist entries through DOM APIs. - If formatted HTML is genuinely required, sanitize it with a mature HTML sanitizer configured to reject scripts, event attributes, dangerous URL schemes, SVG, and other active content. 4. **Add a restrictive Content Security Policy** - Block remote resources and unsolicited network destinations. - Avoid permitting arbitrary inline script execution. - Move the existing inline JavaScript into a local script file or authorize it with a cryptographic hash or nonce. - A suitable baseline is: ```http Content-Security-Policy: default-src 'none'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; script-src 'self'; connect-src 'none'; base-uri 'none'; form-action 'none' ``` 5. **Add security regression tests** - Test every placeholder with closing tags, quotes, event handlers, script tags, SVG payloads, and `javascript:` URLs. - Verify that malicious values appear only as literal visible text. - Validate the completed HTML before delivery and reject unexpected active elements or event-handler attributes. ]]>
