01Issue
Overview
CSV files store values in rows and columns, but spreadsheet programs may treat some cell values as formulas. CSV injection happens when untrusted text in an exported cell is interpreted as a formula when a user opens the file. Quoting a CSV field protects its row and column structure; it does not always stop spreadsheet formula evaluation.
Common causes
- Exports include user-controlled values without accounting for formula-leading characters.
- The application assumes CSV quoting alone makes every value safe in spreadsheet software.
- Export checks are performed on the raw file but not by opening it in the spreadsheet programs users rely on.
- Different spreadsheet applications handle leading whitespace and formula markers differently.
References: OWASP: CSV Injection ↗CWE-1236: Formula Elements in CSV Files ↗
02Examples
Illustrative test record value: =1+1. Export that record and inspect the CSV, then open it in a supported spreadsheet. If the cell displays the calculated result rather than the literal text, the spreadsheet evaluated it. A raw CSV containing the characters is not by itself proof that every spreadsheet will evaluate them.
03Impact
An attacker-controlled value must be included in a downloadable export, and a recipient’s spreadsheet application must interpret that cell as a formula. A formula-like string in a raw file is an indicator; verify how supported spreadsheet software opens it.
If a cell is evaluated as a formula, it may display misleading information or, in some spreadsheet configurations, cause additional behavior such as opening a link. Do not claim code execution or data exfiltration unless that exact behavior is demonstrated in the supported application and configuration.
04Testing
Test cases
1. Check whether exported values become formulas
Place a formula-like value in a test record, export it, and open the file in the spreadsheet applications the product supports. Check whether the cell is treated as text or evaluated.
Example: The text =1+1 is a simple calculation. A raw CSV containing those characters does not prove the spreadsheet evaluates them.
POST /api/contacts HTTP/1.1
Host: app.example.test
Content-Type: application/json
{"name":"=1+1"}
2. Check alternate leading characters and field boundaries
Compare values beginning with =, +, -, and @, and test leading whitespace where relevant. Inspect both the raw export and spreadsheet interpretation.
Example: An export can quote CSV fields correctly and still allow formula interpretation. These are separate checks.
POST /api/contacts HTTP/1.1
Host: app.example.test
Content-Type: application/json
{"name":"+1+1"}
3. Compare export routes and applications
Repeat on reports and exports that use the same user-controlled fields. Compare supported spreadsheet applications and document their behavior.
Example: Different spreadsheet products may handle the same value differently. State which application and version were used.
Testing references: OWASP: CSV Injection ↗CWE-1236: Formula Elements in CSV Files ↗
05Mitigation
Treat CSV structure and spreadsheet formulas as separate concerns. Escape delimiters, quotes, and line breaks according to CSV rules, then apply a tested strategy to make untrusted values display as text in supported spreadsheet products. Prefer a well-maintained export library, document the target applications, and test leading whitespace and Unicode variants. Do not rely on CSV quoting alone.
Retest
Export the same formula-like values and open the files in each supported spreadsheet application. Confirm cells display inert text, columns remain correctly aligned, and ordinary values are unchanged.