T09 · Insecure Skill Coding Practices
- Location
assets/review-template.html:141- Finding
Unescaped Model JSON Embedding Enables Stored Script Injection
- Content
View full analysis
``` The corresponding generation instructions are: ```markdown 不要手写报告 HTML。生成 JSON,替换 `assets/review-template.html` 中的 `/*__MODEL_JSON__*/`,写入 `$TMPDIR/semantic-review-.html`。 模板离线自足,无 CDN、无网络。 ``` The embedded data is subsequently parsed as JSON: ```javascript function App(){ var model = JSON.parse(document.getElementById('model').textContent); var decisionMap = {}; var modelErrors = []; ``` ### Technical Analysis A `script` element is terminated by the HTML parser when it encounters the character sequence ` ``` and the generated JSON is substituted into the placeholder without HTML-safe escaping, the first sequence closes the JSON container. The following `script` element is then interpreted and executed as active JavaScript when the reviewer opens the generated report. The later use of `textContent` and `JSON.parse` does not prevent this issue because script termination occurs during initial HTML parsing, before the application reads the element. ### Attack Path 1. An attacker supplies or modifies an API description, CLI description, schema documen ...[truncated 1633 chars]- Remediation
View remediation
/g, '\\u003e') .replace(/&/g, '\\u0026') .replace(/\u2028/g, '\\u2028') .replace(/\u2029/g, '\\u2029'); ``` Only the resulting `safeJson` value should replace `/*__MODEL_JSON__*/`. 2. **Prefer a representation that cannot terminate an HTML element.** For example, Base64-encode the UTF-8 JSON payload during generation and decode it before `JSON.parse`, or load a separately generated JSON file under an explicitly controlled local workflow. 3. **Add a strict Content Security Policy.** Refactor inline executable scripts to use hashes or nonces, then apply a policy such as: ```html ``` `connect-src 'none'` is particularly appropriate for a report documented as fully offline. CSP should be defense in depth rather than a replacement for safe encoding. 4. **Document the encoding requirement in `references/review.md`.** The generation instructions should explicitly prohibit raw JSON substitution and provide a canonical safe serialization procedure. 5. **Add regression tests** using model values containing: ```text
