T09 · Insecure Skill Coding Practices
- Location
main.js:166- Finding
Unescaped Report Content Permits HTML Injection
- Content
View full analysis
${icon} ${desc} ${status}${detail}`; } // Content that does not match the expected format is displayed directly return `${line}`; ``` Additional affected output locations: ```javascript ${content.section5 ? `${content.section5}` : '(此项暂无内容)
'} ``` ```javascript ${content.section6 ? `${content.section6}` : '(此项暂无内容)
'} ``` ### Technical Analysis The report generator interpolates user-controlled report content directly into an HTML document without HTML encoding or sanitization. Fields such as `desc`, `status`, `detail`, `line`, `content.section5`, and `content.section6` can consequently introduce arbitrary HTML elements and attributes into the generated report. The same underlying pattern is present in other section parsers that construct markup from report text. Input format validation does not provide a security boundary because both formatted and unformatted content is inserted into HTML. An attacker can inject elements such as deceptive links, externally hosted images used for tracking, manipulated visual content, forms, or active HTML features. Most modern email clients block scripts, but this behavior is not universal across preview components and HTML rendering environments. The vulnerability therefore must not be mitigated by relying on recipient-client filtering. ### Attack Path 1. An attacker supplies crafted weekly-report content through one of the collected ...[truncated 1268 chars]- Remediation
View remediation
`, `"`, and `'`. 2. Introduce one centralized escaping function and ensure every section parser uses it: ```javascript function escapeHtml(value) { return String(value) .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"') .replace(/'/g, '''); } ``` 3. Escape parsed values before constructing markup: ```javascript const safeDesc = escapeHtml(desc); const safeStatus = escapeHtml(status); const safeDetail = escapeHtml(detail); ``` 4. Escape unformatted lines and the complete contents of sections 5 and 6 rather than inserting them directly. 5. If limited formatting is required, use a maintained HTML sanitizer with a strict allowlist. Block scripts, event-handler attributes, forms, iframes, unsafe URL schemes, and remote resources. 6. Add security tests using payloads containing `
