T09 · Insecure Skill Coding Practices
- Location
assets/recipe_template.html:473- Finding
Client-Side Script Injection Through Unescaped Template Data and Unsafe HTML Rendering
- Content
View full analysis
`${item.label} ${item.value}` ).join(''); } ``` ```javascript function renderMeals() { const container = document.getElementById('mealsContainer'); container.innerHTML = meals.map(meal => `...[truncated 4090 chars]- Remediation
View remediation
` element. - Read it with `textContent` and parse it using `JSON.parse`. - Alternatively, provide data in a separate local JSON file. 3. **Eliminate unsafe `innerHTML` sinks** - Create elements with `document.createElement`. - Assign all user-derived values through `textContent`. - Set numeric style values only after strict numeric parsing and range validation. - Use `classList` with an allowlist rather than inserting arbitrary values into class attributes. 4. **Sanitize any intentionally supported markup** - If rich HTML is required, process it with a maintained allowlist-based sanitizer. - Disallow scripts, event-handler attributes, dangerous URL schemes, embedded documents, SVG, and MathML unless explicitly required. 5. **Validate generated data** - Enforce schemas for meals, dishes, ingredients, and shopping items. - Apply type checks, length limits, numeric bounds, and allowlists before report generation. 6. **Add defense-in-depth controls** - Apply a restrictive Content Security Policy that blocks inline scripts and limits script and connection sources. - Avoid granting the generated page access to privileged APIs or sensitive same-origin application data. ]]>
