T09 · Insecure Skill Coding Practices
- Location
scripts/em_stock_selector.py:118- Finding
CSV Formula Injection in Exported Stock Data
- Content
View full analysis
- Remediation
View remediation
str: text = str(value if value is not None else "") if text.startswith(("=", "+", "-", "@")): return "'" + text return text ``` Use it for both headers and data: ```python writer.writerow([sanitize_csv_cell(value) for value in display_header]) for row in all_data: writer.writerow([ sanitize_csv_cell(row.get(key, "")) for key in header ]) ``` Additional hardening measures: 1. Treat all remote API fields as untrusted input, even when they come from an expected HTTPS endpoint. 2. Document that generated files contain external data and should be opened using protected-view settings. 3. Add unit tests covering cells beginning with `=`, `+`, `-`, and `@`, including values preceded by tabs or other whitespace that spreadsheet applications may ignore. 4. Consider sanitizing leading control characters and whitespace before checking for formula prefixes. 5. If preserving exact raw values is required, export to a format with explicit string cell types, such as a properly generated XLSX file, instead of relying on CSV interpretation. ]]>
