T09 · Insecure Skill Coding Practices
- Location
eval-viewer/generate_review.py:279- Finding
Stored Script Injection Through Embedded Evaluation Data
- Content
View full analysis
// ---- Embedded data (injected by generate_review.py) ---- /*__EMBEDDED_DATA__*/ ``` ### Technical Analysis `generate_html()` serializes evaluation data with `json.dumps()` and inserts the result directly into an executable HTML ``. An evaluated output containing a payload such as: ```html ``` would terminate the original script element before JavaScript parsing and introduce a new executable script element. Although most viewer rendering uses `textContent`, that protection occurs only after `EMBEDDED_DATA` has been parsed. It does not protect the initial server-generated script block. ### Attack Path 1. An untrusted or compromised Skill is included in an evaluation. 2. The Skill generates a text output containing a `` sequence followed by attacker-controlled JavaScript. 3. `embed_file()` reads the generated output and includes it in the `embedded` data structure. 4. `generate_html()` serializes the structure and places it directly inside the viewer’s executable script block. 5. The user opens or refreshes the evaluation viewer. 6. The browser terminates the intended script block and executes the injected JavaScript in th ...[truncated 998 chars]- Remediation
View remediation
``` Then retrieve and parse its text: ```javascript const EMBEDDED_DATA = JSON.parse( document.getElementById("embedded-data").textContent ); ``` 3. Before embedding JSON into HTML, escape characters significant to the HTML parser. At minimum: ```python data_json = ( json.dumps(embedded) .replace("&", "\\u0026") .replace("<", "\\u003c") .replace(">", "\\u003e") .replace("\u2028", "\\u2028") .replace("\u2029", "\\u2029") ) ``` Escaping `<` prevents creation of a literal `` sequence. 4. Add regression tests using output values containing: ```text
