T09 · Insecure Skill Coding Practices
- Location
scripts/build_quiz_html.py:1051- Finding
HTML and JavaScript Injection Through Unescaped Custom Configuration
- Content
View full analysis
__JS_CORE__ ... ``` ### Technical Analysis The HTML generator supports custom configuration files through the documented `--config`, `--houses`, `--questions-file`, and `--glossary` options. Values loaded from those files are collect ...[truncated 3289 chars]- Remediation
View remediation
", "\\u003e") .replace("\u2028", "\\u2028") .replace("\u2029", "\\u2029") ) ``` Use this function for `payload`, `wide`, and `zero` before inserting them into an inline script. 2. **HTML-escape every value inserted into markup contexts.** In particular: ```python import html safe_page_title = html.escape(page_title, quote=True) html_output = HTML_TEMPLATE.replace("__PAGE_TITLE__", safe_page_title) ``` Apply equivalent escaping to every template substitution according to its destination context. 3. **Prefer a non-executable data container.** Place configuration data in a dedicated element: ```html ``` The JSON must still escape `<`, `>`, and `&`. Parse it with: ```javascript const QUIZ = JSON.parse(document.getElementById('quiz-data').textContent); ``` 4. **Treat custom configuration files as untrusted input.** Validate all string fields and reject control sequences or unexpected markup where HTML is not intended. 5. **Add regression tests.** Generate pages using values containing: - `` - `` - `<`, `>`, `&`, single quotes, and double quotes - U+2028 and U+2029 - Closing `` and `` sequences Tests should assert that these values remain inert text and that no additional script or markup elements are created. 6. **Consider a restrictive Content Security Policy.** A CSP can provide defense in depth, although it should not replace contextual output encoding. For a self-contai ...[truncated 129 chars]
