T09 · Insecure Skill Coding Practices
- Location
scripts/main.py:728- Finding
Stored HTML Injection Through Unescaped Dataset-Controlled Gene Names
- Content
View full analysis
{gene}Expression: {stats.get('total_counts', 'N/A')} counts | Detection rate: {stats.get('detection_rate', 0):.1%}""" ``` The same untrusted value is also inserted into the statistics table: ```python for gene in genes[:10]: if gene in self.gene_names: stats = self.get_spatial_stats(gene) html_content += f""" {gene} {stats.get('total_counts', 0):,} {stats.get('mean_expression', 0):.4f} {stats.get('max_expression', 0):.1f} {stats.get('detection_rate', 0):.1%} """ ``` ### Technical Analysis Gene names are obtained from the loaded transcriptomics dataset and can therefore be controlled by the creator of that dataset. `generate_report()` interpolates these values directly into HTML text nodes and quoted HTML attributes without context-appropriate escaping. A malicious gene name containing HTML syntax, such as: ```text ">``` can terminate the existing attribute and inject a new active HTML element. The resulting payload is stored in `spatial_report.html` and executes when a user opens the report in a browser. The vulnerability affects both the gene card and statistics table. It does not require command execution on the host; exploitation occurs in the browser co ...[truncated 1207 chars]
- Remediation
View remediation
{safe_gene}""" ``` 3. Prefer a maintained template engine with automatic escaping, such as Jinja2 with autoescaping enabled, rather than manually concatenating HTML. 4. Validate gene identifiers against an expected character set where practical. This should supplement, not replace, output encoding. 5. Generate image filenames independently from display names, such as with a random identifier or validated slug. 6. Add tests using gene names containing quotation marks, angle brackets, ampersands, and event-handler payloads. Verify that the generated report contains encoded text rather than executable markup. 7. Consider adding a restrictive Content Security Policy to the generated report as defense in depth, while retaining proper HTML escaping as the primary fix. ]]>
