T09 · Insecure Skill Coding Practices
- Location
references/html_template.md:40- Finding
Unescaped Dynamic Content in Generated HTML
- Content
View full analysis
{出发地} → {目的地} | 全能旅行规划师 ``` ```html{出发地} → {目的地}
``` ```html {出发地} → {目的地} ``` The template usage instruction at line 709 states: ```text 1. **数据填充**:将模板中所有 `{变量}` 替换为实际搜集的数据 ``` This instruction requires every template variable to be replaced with collected data, but it does not require contextual encoding, validation, or sanitization. ### Technical Analysis The HTML-generation workflow inserts values obtained from users and web searches directly into HTML contexts. The same unsafe substitution pattern is used in document titles, text elements, tables, attributes, and other sections throughout the template. HTML treats substituted values as markup rather than plain text. For example, a malicious origin or destination value could contain: ```html``` If this value is inserted without encoding, it closes the existing element and creates an executable `script` element. Values sourced from search results present a similar risk if compromised or attacker-controlled pages cause executable markup to be incorporated into the itinerary. The template also permits inline JavaScript, so there is no effective Content Security Policy preventing injected inline scripts from running. The generated file is explicitly intended to be opened through a file-presentation tool or browser preview, creating an execution point for the injected content. ### Attack Path 1. An attacker supplies a crafted travel field, such as an origin, destination, hotel name, restaurant name, or itinerary note containing HTML or Jav ...[truncated 1321 chars]
- Remediation
View remediation
` as `>`. - Encode `"` as `"`. - Encode `'` as `'`. 2. Use a template engine that enables automatic HTML escaping by default rather than performing unrestricted string replacement. 3. Validate fields according to their expected formats: - Permit only reasonable city and destination characters and lengths. - Parse prices, percentages, durations, and ratings as numeric values. - Permit only explicitly approved URL schemes and domains for links. - Reject control characters and executable URL schemes such as `javascript:`. 4. Treat all user input and web-search content as untrusted. Add explicit Skill instructions prohibiting the direct inclusion of HTML, scripts, event-handler attributes, or executable URLs from those sources. 5. Avoid inserting dynamic values into inline JavaScript. If data must be exposed to JavaScript, serialize it with a safe JSON encoder and place it in a non-executable data element. 6. Add a restrictive Content Security Policy. Prefer external or hashed first-party scripts and disallow arbitrary inline execution. 7. Add security tests using payloads in every template field, including: ```htmlOpen ``` The generated output should display these values only as inert text. ]]>
