CleanCSV

CSV Injection Explained: Why Exported Cells Get an Apostrophe

Updated 2 min read

If you have exported data and found an apostrophe in front of some values, such as '=SUM(A1:A3), you have met protection against CSV injection, also called formula injection. Here is what it guards against, how it can damage legitimate data, and when you can safely turn it off.

What is CSV injection?

Spreadsheet programs treat a cell that starts with =, +, - or @ as a formula. A CSV file has no way to say “this is just text”, so a value typed into a web form, such as a name or a comment, can become a live formula when someone later exports the data and opens it in Excel, LibreOffice or Google Sheets.

A malicious formula can, for example, create a link that sends the contents of other cells to an outside website when clicked, or show misleading content to the person reading the sheet. Older attacks abused features that could start other programs; modern Excel blocks or warns about most of those, but formulas that leak data or trick the reader still work.

Who should care

Anyone who exports data that came from other people: sign-up forms, survey answers, support tickets, user profiles or marketplace listings. The person at risk is whoever opens the export in a spreadsheet, and that is often someone on your own team.

How the apostrophe helps

An apostrophe at the start of a value tells spreadsheet programs to treat it as text. The OWASP guidance on CSV injection recommends prefixing any cell that starts with =, +, -, @, a tab or a carriage return this way, and quoting every field.

The catch: real data starts with + and - too

A blanket rule also changes negative numbers like -12.50 and international phone numbers like +44 20 7946 0958, which breaks imports and calculations. CleanCSV's protection is narrower. Values that start with = or @ are always prefixed. Values that start with + or - are only prefixed when they contain something other than digits, spaces and the punctuation used in numbers and phone numbers. So -12.50 and +1 (555) 010-2030 stay exactly as they are, while -2+3, which Excel would calculate, gets an apostrophe.

When to turn protection off

  • The file goes into a database, a script or an API rather than a spreadsheet, where the apostrophe would become part of the data.
  • You trust every value in the file, for example data you typed yourself.
  • You need an exact round trip, such as re-importing into the same system.

In CleanCSV, untick Protect against formula injection in the download section. Excel (.xlsx) downloads do not need the protection at all: their cells are stored explicitly as text, so a value starting with = is displayed as text and never calculated. That makes converting to Excel the safest way to share untrusted data with spreadsheet users.