T09 · Insecure Skill Coding Practices
- Location
templates/horoscope-cover.html:60- Finding
Unescaped template interpolation permits HTML and active-content injection
- Content
View full analysis
{{title}} ...{{badge}}{{lucky_char}}{{date}}宜 {{yi}}忌 {{ji}}财神方位 {{caishen}}吉时 {{jishi}}{{advice}}``` `templates/horoscope-cover.html:5, 60-70`: ```html {{title}} ...{{header}}{{title}}{{emoji}}{{subtitle}}{{content}}{{footer}}``` `templates/zodiac-cover.html:5, 62-70`: ```html {{title}} ...{{badge}}{{emoji}}{{title}}{{subtitle}}{{content}}{{footer}}``` ### Technical Analysis The templates place variable values directly into HTML text and document-title contexts. The `{{conten ...[truncated 2942 chars]- Remediation
View remediation
`, `"`, and `'` before inserting titles, subtitles, dates, labels, footer text, advice, emoji values, and other user-controlled strings. 2. **Eliminate unrestricted `{{content}}` fragments.** Represent rankings and tips as structured arrays, then create the required elements using safe DOM APIs such as `document.createElement()` and `textContent`. Do not construct these sections through untrusted `innerHTML` or raw string concatenation. 3. **Apply strict sanitization if formatted HTML is required.** Use a maintained sanitizer with a minimal allowlist. Reject scripts, event-handler attributes, iframes, object/embed elements, SVG/MathML, forms, URL-bearing elements, CSS injection, and dangerous URL schemes. 4. **Harden Playwright rendering.** - Disable JavaScript when it is unnecessary. - Intercept requests and reject all network access, or allow only explicitly required local resources. - Use a fresh isolated browser context for every rendering operation. - Preserve Chromium sandboxing and run the renderer as a low-privilege account. - Apply navigation and rendering timeouts. 5. **Define field limits.** Enforce maximum lengths, expected data types, and character constraints where appropriate to reduce denial-of-service and layout-manipulation risks. 6. **Add security tests.** Test all placeholders with element-closing payloads, script tags, event handlers, external images, iframes, SVG payloads, malformed markup, and dangerous URL schemes. Verify that the generated document contains only encoded text and makes no outbound requests. 7. **Document the trust boundary.** Update `SKILL.md` to state that input is untrusted, define the required escaping process, and identify which fields—if any—may contain sanitized formatting. ]]>
