T09 · Insecure Skill Coding Practices
- Location
mx_select_stock.py:108- Finding
Spreadsheet Formula Injection in Generated CSV Files
- Content
View full analysis
- Remediation
View remediation
str: if value is None: return "" if isinstance(value, (dict, list)): text = json.dumps(value, ensure_ascii=False) else: text = str(value) candidate = text.lstrip(" ") if candidate.startswith(DANGEROUS_CSV_PREFIXES): return "'" + text return text ``` Sanitize both headers and values before writing: ```python safe_fieldnames = [neutralize_csv_cell(name) for name in fieldnames] with open(csv_path, "w", newline="", encoding="utf-8-sig") as f: writer = csv.DictWriter( f, fieldnames=safe_fieldnames, extrasaction="ignore", ) writer.writeheader() for row in rows: safe_row = { neutralize_csv_cell(key): neutralize_csv_cell(value) for key, value in row.items() } writer.writerow(safe_row) ``` Becau ...[truncated 174 chars]
