CSV exports that run formulas when opened in a spreadsheet (CSV injection)

Last updated November 12, 2026
Steps
- Find every place your app creates CSV or spreadsheet files: admin export buttons, scheduled report emails, “download my data” features and any code that uses a CSV library or joins values with commas.
- Use a real CSV library (for example csv-stringify or Papa Parse in Node, Python’s csv module) instead of joining strings, and quote every field, doubling any double quotes inside it.
- For fields that came from users, if the value starts with =, +, -, @, a tab, a carriage return or a line feed, prefix it so the spreadsheet reads it as text. OWASP and MITRE describe prepending a single quote; OWASP also describes a tab-character prefix inside the quoted field as more resistant in Excel.
- Remember that attackers can use separators and quotes to start a new cell, so apply the check to every cell after proper quoting, not just to the start of the raw input.
- Watch for full-width look-alike characters (= + - @), which OWASP notes some locales treat as formula starters.
- Don’t trust that a numeric-looking field is safe: phone numbers starting with + and negative amounts are common, so handle them deliberately (for example, store phone numbers as text and decide how amounts should appear).
- Retest: put =1+2 and @SUM(1,1) in a name or message field, export, open the file in your spreadsheet app, and confirm they show as plain text.
Why it matters
MITRE’s CWE-1236 describes a product that saves user-provided information into a CSV file without neutralizing elements a spreadsheet could interpret as a command. Its observed examples include CVE-2019-12134 (CSV injection through a contact-form field) and CVE-2019-17661 (formula code in a first or last name). OWASP says malicious formulas can be used to exploit spreadsheet software, to exploit people’s habit of clicking through warnings in files from their own website, or to exfiltrate contents of the spreadsheet. Both note there is no perfect fix because spreadsheet programs behave differently, and OWASP warns that some escaping can be undone when Excel saves and reopens a file. Escaping at export time still removes most of the risk. This page is for checking and fixing your own app.
Sources
OWASP: CSV Injection — https://owasp.org/www-community/attacks/CSV_Injection
MITRE CWE-1236: Improper Neutralization of Formula Elements in a CSV File — https://cwe.mitre.org/data/definitions/1236.html
Checked at the source on November 12, 2026.
Related patterns
- Rendering user or AI output as raw HTML (XSS)
- SQL built from strings in raw queries (SQL injection)
- OS command injection from unsanitized shell calls
- Passwords, tokens and personal data written to your logs
- API responses that return whole database records (excessive data exposure)
- Mass assignment: users can set fields like role or is_admin
Found a problem you'd rather not fix yourself?
Tell us what's wrong. A StorenTech engineer reviews your app and replies with a fixed quote, so you know the cost before any work starts.
Get it fixed by StorenTechVibe Security Weekly
One email a week with new failure patterns and how to fix them.
By joining you agree we may email you this newsletter. See our privacy policy. Free. Unsubscribe anytime. We'll never sell your email.