T09 · Insecure Skill Coding Practices
- Location
tools/visualization.py:229- Finding
Stored HTML and JavaScript Injection in Generated Performance Reports
- Content
View full analysis
绩效评价报告 - {data.get('industry', '')} ``` ```python{data.get('industry', '')} · {data.get('size', '')}``` ```python for key, res in ind_results.items(): level_class = f"level-{res['level'][0].lower()}" if res['level'] else "" html += f""" {res.get('indicator', key)} {res.get('value', '-')} {res.get('unit', '')} {res.get('level', '-')} {res.get('score', '-')} """ ``` ```python with open(output_path, 'w', encoding='utf-8') as f: f.write(html) ``` ### Technical Analysis The HTML report generator interpolates report data directly into HTML markup without escaping it for the relevant HTML context. Affected fields include: - `industry` - `size` - Indicator names and keys - Indicator values and units - Evaluation levels and scores - The dynamically constructed `class` attribute These values can originate from the dictionary supplied to `generate_full_report()`. In normal use, the industry value may originate from user-provided analysis parameters and is retained in the diagnosis result. Because the generator does not encode characters such as `<`, `>`, `"`, `'`, and `&`, crafted content can terminate the intended HTML element or attribute and introduce new executable markup. For example, an industry value resembling the following would break out of the report's title element: ```html ``` The resulting payload is persisted in the generated HTML file. It executes when a recipient opens that file in a browser. The generated document has no Content Security Policy that would prevent inline scr ...[truncated 1580 chars]- Remediation
View remediation
``` 7. Add regression tests covering payloads in every dynamic field, including: ```html ">``` The tests should verify that payloads appear only as encoded text and do not create executable DOM elements. ]]>
