T09 · Insecure Skill Coding Practices
- Location
scripts/export_csv.py:95- Finding
Spreadsheet Formula Injection in CSV Exports
- Content
View full analysis
- Remediation
View remediation
str: text = "" if value is None else str(value) if text.lstrip().startswith(FORMULA_PREFIXES): return "'" + text return text ``` 2. Apply the function to every string written to both observation and summary CSV files: ```python writer.writerow([safe_csv_cell(row[k]) for k in OBS_FIELDNAMES]) ``` ```python w.writerow([ safe_csv_cell(species), len(by_species[species]), safe_csv_cell(first), safe_csv_cell(last), ]) ``` 3. Apply the protection to all exported fields, not only species and notes. Location names, timestamps, image paths, and data imported from existing `bird.json` files must also be treated as untrusted. 4. Add regression tests covering values beginning with `=`, `+`, `-`, and `@`, including values with leading whitespace and values exported through the summary path. 5. Document that exported CSV content is neutralized for spreadsheet safety. If preserving exact raw values is required, provide an explicit opt-in raw export mode with a security warning rather than leaving unsafe behavior as the default. 6. Consider exporting XLSX files through a library that explicitly stores untrusted values as text when spreadsheet compatibility is required. ]]>
