Home / patterns

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

An office manager opening a spreadsheet on a laptop as a plain warning dialog appears over a blurred grid of cells, a developer colleague leaning in to look, coffee mug and printed reports on the desk, daylight office, no brand logos
Quick answer: Almost every AI-built dashboard gets an “Export to CSV” button: orders, signups, contact-form messages, bookings. The generated code usually joins user-entered fields straight into the file. If a customer types a name or message that starts with =, +, - or @, a spreadsheet program like Excel or LibreOffice Calc may treat it as a formula when your teammate opens the export. OWASP calls this CSV or formula injection, and MITRE lists it as CWE-1236, with real CVEs from contact-form fields and first or last names. Crafted formulas can try to pull data out of the sheet or push the person opening it to approve dangerous prompts. The fix is to neutralize risky leading characters and quote every field when you build the file.

Last updated November 12, 2026

Steps

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. Watch for full-width look-alike characters (= + - @), which OWASP notes some locales treat as formula starters.
  6. 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).
  7. 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

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 StorenTech

Vibe 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.