T09 · Insecure Skill Coding Practices
- Location
services/html_export.py:361- Finding
Stored Script Injection in Exported and Served Citation Graphs
- Content
View full analysis
"GraphData": with open(path) as f: data = json.load(f) paper_fields = {f.name for f in Paper.__dataclass_fields__.values()} nodes = [] for n in data.get("nodes", []): filtered = {k: v for k, v in n.items() if k in paper_fields} nodes.append(Paper(**filtered)) ``` ### Technical Analysis `json.dumps()` produces valid JSON but does not make that JSON safe for direct inclusion in an HTML `` sequence terminates the script element even when it occurs inside a JavaScript string. An attacker-controlled paper title, abstract, author, identifier, source, or pre-generated summary containing a closing script tag can therefore escape the generated data structure and inject a new script element. Relevant data can originate from ...[truncated 1473 chars]- Remediation
View remediation
` as `\u003e` - `&` as `\u0026` - U+2028 as `\u2028` - U+2029 as `\u2029` 3. Prefer placing serialized data in a non-executable element: ```html ``` Then read and parse its `textContent`. The JSON still must escape `<` to prevent `` termination. 4. Apply the same safe serializer to paper data, nodes, edges, classifications, seed identifiers, distributions, and pre-generated summaries. 5. Add a restrictive Content Security Policy that disallows inline and untrusted scripts. Use nonces or hashes where inline scripts remain necessary. 6. Add regression tests using values containing ``, HTML tags, quotes, U+2028, and U+2029. 7. Treat metadata from scholarly APIs, PDFs, BibTeX, Zotero, and imported graph files as untrusted. ]]>
