All guides

CSV injection: prevent formulas in catalogue exports

Stop catalogue fields starting with =, +, - or @ running as formulas. Keep the raw CSV for imports, give reviewers typed text cells, test a reopened copy.

Method7 min read
A practical guide to reviewing your catalogues.
View sources
In this guide 7 sections

CSV injection, also called formula injection, happens when a field in an exported CSV starts with a character such as =, +, - or @ and the spreadsheet that opens the file treats it as a formula. To prevent it in catalogue exports, keep the raw CSV for application imports and give human reviewers a workbook with explicitly typed text cells, then check the saved and reopened copy in the application your team uses.

Supplier catalogues are exposed because they carry text you did not write: descriptions, labels, marketing copy and notes typed by many people upstream. A harmless-looking product label can become an active cell the moment someone double-clicks the export.

What is CSV injection in a catalogue export?

OWASP’s CSV injection page describes the problem as untrusted input embedded in a CSV file, which a spreadsheet may then interpret as formulas. CSV itself has no cell types: every field is text until the program that opens it decides otherwise. That decision is the risk.

Which characters trigger a formula?

OWASP lists these leading characters as able to start a formula:

Leading characterExample of a field that needs attention (synthetic)
= equals=1+1 typed in a supplier note
+ plus+33 1 23 45 67 89 as a phone number in a contact column
- minus-20% pack promotion at the start of a description
@ at sign@sales team in a comment field
Tab, carriage return, line feedA description pasted with an invisible leading control character

OWASP also notes that full-width variants of =, +, - and @ may be read as formulas in some locales. Treat them as part of the same check.

What can go wrong?

OWASP lists three risks: exploiting a vulnerability in the spreadsheet software, persuading a user who trusts the source to ignore a security warning, and extracting data from the open spreadsheet or other open spreadsheets. In a catalogue workflow there is a quieter failure as well: a legitimate value such as -20% pack promotion or +33… gets evaluated or reformatted, and the reviewer approves a row that no longer matches the supplier file.

How to prevent CSV injection in catalogue exports

The safest pattern is to stop using one file for two jobs. Give each file a single recipient and contract:

FileRecipient and contract
Raw CSVApplication import. Keep the agreed fields and their original values, unmodified.
Viewing workbookHuman review. Write identifiers and descriptions as text cells and validated amounts as numeric cells.
Calculation workbookA separate, approved workflow with its own validation rules.

Label each file by purpose and keep the raw CSV as the import source. This also protects identifiers such as 00127, which a viewing file could otherwise turn into the number 127; the same rule underpins normalising product codes without losing leading zeros.

Before any file is written, parse the input with the agreed encoding, delimiter and quote handling for CSV imports. When you compare two supplier editions, read the differences from a report rather than from a spreadsheet that may have evaluated a cell: the sample catalogue difference report shows the kind of side-by-side view a reviewer needs.

Does escaping the CSV prevent formula injection?

Escaping helps for files meant only for viewing, but it is not a complete fix. OWASP describes two approaches:

  1. Make each field read as text: wrap it in double quotes, prepend a single quote and double any double quote inside it.
  2. For cells starting with =, +, - or @, add a tab character inside the quoted field.

Both have limits that matter for catalogue data:

  • Saving and reopening. OWASP warns that Excel may remove quotes or escape characters when a CSV is saved and reopened, so an escaped formula can become active again.
  • The data changes. A prepended quote or tab stays in the value. If that file is later imported, the item code or description no longer matches the supplier record. Never escape the raw import CSV.
  • Separators. A field separator such as , or ; inside an unquoted field can start a new cell, so quoting must be correct before any escaping is meaningful.
  • No universal rule. OWASP states that no single sanitisation strategy works for every spreadsheet application and downstream consumer.

Apply escaping to text columns only. A validated negative amount in a numeric price or discount column is data, not an attack: write it as a number in the viewing workbook rather than prefixing it and turning the price into text.

Validate the structure before generating the workbook

Check column names, field counts and required values against the agreed schema. A delimiter inside a properly quoted field belongs to that field. Hold records that fail the schema review and log the reason before generating the viewing file.

Write text using your generator’s text-cell operation. SpreadsheetML, the XML format inside an .xlsx workbook, gives each cell a declared type, such as a shared string, an inline string or a number, and stores a formula in a separate element of the cell (ECMA-376, Part 1 §§18.3.1.4 and 18.18.11). Check that the writer produced the intended cell type, not only the expected display.

Test the saved file and the reopened copy

Use a small fixture containing catalogue text, the leading characters above and ordinary numeric values. Verify the file immediately after export, then save and reopen a copy in the intended application. For each text cell, check its declared type, its exact value and the absence of a formula. Compare both checks with the raw record.

Synthetic inputExpected check
=1+1 in a supplier noteThe cell is text and displays =1+1, not 2.
-20% pack promotion as a descriptionThe cell is text, starts with the minus sign and contains no formula.
00127 as a product codeThe cell contains five text characters, including both leading zeros.
REF;42 as a supplier labelThe label stays in one text cell.
Équerre "Pro" as a descriptionThe accent and literal quotation marks are preserved.
-12.50 in a validated discount columnThe stored value is numeric and keeps its sign.
A record missing a required fieldThe row is held and the reason appears in the validation log.

Record the application and version, field, expected value, actual type and result after reopening. Hold the viewing export if a text cell has become a formula or a number, or if the stored value differs from the confirmed source. Add the fixture to your ERP supplier catalogue import checklist so it runs again after every change to the export.

If the receiving workflow requires CSV

Agree the spreadsheet import method and the text column types with the recipient. Because quote-based protection can be lost after saving and reopening, run the same fixture in the recipient’s workflow and hold the viewing file if its text fields fail. Keep the application import CSV separate and unchanged.

Formulas you deliberately keep belong in a separate, approved source workbook. There, review each formula and the calculated value stored in the file before anything reads it.

Frequently asked questions

Is CSV injection the same as formula injection?

Yes. Both names describe the same problem: a field in a CSV file that a spreadsheet interprets as a formula when the file is opened.

Which characters can start a formula in a CSV file?

OWASP lists the equals sign, plus, minus, the at sign, tab, carriage return and line feed at the start of a field. Full-width versions of the first four may also be read as formulas in some locales.

Do double quotes around a field prevent CSV injection?

Not on their own. Quotes keep a field together during parsing, but the spreadsheet can still evaluate the content, and quoting or escaping can be lost when the file is saved and reopened.

Should I escape negative prices in a catalogue export?

No. Escape text columns only and write validated amounts as numbers in the viewing workbook, otherwise a negative discount becomes text and stops calculating.

Should the CSV used for an ERP import be sanitised?

Keep the import CSV unmodified and validate it against the agreed schema instead. Sanitising adds characters to the values, so codes and descriptions would no longer match the supplier file.

Official sources & scope

This guide describes a working method. The examples are fictional; the official documentation remains the reference for the format rules. CatalogInspect is an independent service.

Back to guides & resources

Request access to CatalogInspect.

Enter your work email address to request access to CatalogInspect.

Submitting sends your request to BankStatementLab’s infrastructure for CatalogInspect. It does not create an account, trigger a payment or send an automatic email. Privacy.