T09 · Insecure Skill Coding Practices
- Location
eval-viewer/generate_review.py:267- Finding
Stored JavaScript Injection in the Generated Evaluation Viewer
- Content
View full analysis
// ---- Embedded data (injected by generate_review.py) ---- /*__EMBEDDED_DATA__*/ ``` ### Technical Analysis The generator recursively reads evaluation output files and includes text-file contents, prompts, grading data, and previous feedback in `embedded`. It serializes this object using `json.dumps()` and inserts the resulting JSON directly into an HTML `` can therefore terminate the enclosing script element, after which attacker-controlled HTML or JavaScript can be interpreted by the browser. The vulnerable data can originate from a Skill being evaluated. Consequently, an untrusted Skill can place the payload in an output file without requiring direct modification of the viewer. ### Attack Path 1. An attacker supplies a Skill or evaluation task that generates a text output containing a script-closing sequence and attacker-controlled markup. 2. The output is saved under an evaluation run's `outputs/` directory. 3. `find_runs()` and `embed_file()` read the output and add its contents to the `runs` structure. 4. `generate_html()` serializ ...[truncated 987 chars]- Remediation
View remediation
SAFE_JSON ``` 3. Before placing JSON into HTML, escape characters significant to the HTML parser: ```python data_json = json.dumps(embedded) data_json = ( data_json .replace("<", "\\u003c") .replace(">", "\\u003e") .replace("&", "\\u0026") .replace("\u2028", "\\u2028") .replace("\u2029", "\\u2029") ) ``` 4. Prefer a templating library with explicit HTML-context escaping rather than raw string replacement. 5. Add a restrictive Content Security Policy that disallows arbitrary inline scripts and limits network destinations. 6. Add regression tests containing ``, HTML tags, event handlers, and Unicode line separators in prompts and output files. ]]>
