T09 · Insecure Skill Coding Practices
- Location
scripts/script.sh:201- Finding
Spreadsheet Formula Injection in CSV Export
- Content
View full analysis
portfolio.csv ``` 4. The resulting file contains a formula-like cell: ```csv ticker,quantity,avg_price,value,date_added =1+1,10.0,100.0,1000.0,2026-09-12 ``` 5. When the CSV file is opened in compatible spreadsheet software, the ticker cell may be evaluated as a formula. 6. A more capable spreadsheet formula ...[truncated 856 chars]- Remediation
View remediation
&2 return 1 fi ``` 2. Generate CSV output with Python's standard `csv` module instead of manual string interpolation: ```python import csv import sys writer = csv.writer(sys.stdout) writer.writerow(['ticker', 'quantity', 'avg_price', 'value', 'date_added']) ``` 3. Neutralize spreadsheet formulas in every textual CSV field. Prefix values beginning with `=`, `+`, `-`, or `@` with an apostrophe: ```python def spreadsheet_safe(value): text = str(value) if text.startswith(('=', '+', '-', '@')): return "'" + text return text ``` 4. Apply neutralization to all attacker-controlled textual fields, including values loaded from pre-existing or manually modified JSON files. 5. Add regression tests covering formula prefixes, commas, quotation marks, line breaks, and ordinary ticker symbols. ]]>
