T09 · Insecure Skill Coding Practices
- Location
scripts/batch_report.py:318- Finding
Stored HTML and JavaScript Injection in Generated Reports
- Content
View full analysis
// Data is inserted directly into an executable script context. var ROWS = {rows_json}; ``` ```javascript var sigText = r.signal || ''; var sigDisplay = sigText ? ('' + sigText + '') : '-'; html += '' + '' + r.code + '' + '' + r.name + '' + sigDisplay + '' + vbtV + '' + '' + r.best_name + '' + '' + statusCell + '' + ''; document.getElementById('table-body').innerHTML = html; ``` The individual report generator contains a second unsafe HTML interpolation path: ```python # scripts/report.py label = f"{ticker} {stock_name}" if stock_name else ticker html = f""" {label} - VectorBT 向量化回测分析报告 ...{label} - VectorBT 向量化回测分析报告
... """ with open(out_path, 'w', encoding='utf-8') as f: f.write(html) ``` ### Technical Analysis Stock names, signal text, report filenames, strategy names, and other values originating from CSV/XLS input or external market-data services are embedded into generated HTML without context-sensitive escaping. `json.dumps()` produces valid JSON, but it does not make arbitrary strings safe inside an HTML `- Remediation
View remediation
`, `&`, U+2028, and U+2029. Prefer placing JSON in a non-executable element and parsing its `textContent`. 5. Validate tickers against the documented six-digit A-share format. 6. Treat names and signals from CSV files and external APIs as untrusted data. 7. Add a restrictive Content Security Policy that disallows inline scripts and event handlers. Use a nonce or external local script where scripting is required. 8. Add regression tests using payloads containing HTML tags, quotes, event handlers, ``, and encoded variants. ]]>
