Back to the blog Data governance

Can You Safely Open This App’s CSV Export? Test for Spreadsheet Formula Injection

CSV files are text, but spreadsheet software may interpret some cell values as formulas. Learn how to test realistic exports and handle untrusted values cautiously.

A team checks a CSV export in a text editor and a spreadsheet before sharing it

Why a CSV value can behave differently in a spreadsheet

A CSV file stores text in cells separated by delimiters. A spreadsheet program may do more than display that text: when a cell begins with a formula-like character, the program may interpret its contents as a formula as the file opens. That distinction is the basis of CSV export formula injection.

The risk is worth checking when an application places untrusted content in a CSV or another spreadsheet-compatible export. A value entered by a user—or brought in from another system—might look like ordinary text in the application but be interpreted differently by a spreadsheet.

This is not a reason to treat every CSV as malicious. It is a reason to assess what data can enter the export, who opens the file, and what their spreadsheet software does with it.

  • Prioritize fields that can contain user-controlled or externally supplied text.
  • Check the actual export format and the spreadsheet applications staff use; CSV parsing and spreadsheet formula interpretation are separate steps.
  • Use harmless test values. Do not validate by trying commands or uncontrolled network requests.

Fields and export paths to put on your test list

Start with fields where people or connected systems can supply free-form content. Also include the ways staff obtain exports: a report download, an administrator export, an email attachment, or a scheduled export may follow different paths.

  • Names, email addresses, company details, and other profile fields.
  • Comments, ticket subjects, notes, form submissions, and other free-text answers.
  • Imported or integrated records, including data received through a sync, webhook, or partner feed.
  • Reports and exports that staff share with colleagues or external recipients.

A controlled CSV export test matrix

Use harmless inputs in a test record. Check both what the exported text contains and how each spreadsheet workflow interprets it.

Test caseHarmless test input or conditionWhat to check
Formula-like prefixes=1+1; +1+1; -1+1; @SUM(1,1)Does the target spreadsheet show a calculated result or a formula rather than the literal value?
Other possible prefixesTab, carriage return, line feed, and applicable full-width variantsDoes the spreadsheet or locale in scope interpret the value as a formula?
Cell-boundary charactersA test value containing the export’s separator or quotes, positioned so a formula-like value could followDoes the export parse into an unexpected new cell whose first content is formula-like?
Save and reopenA test file handled through the team’s usual save, close, and reopen workflowDoes a value that looked literal on first open become interpreted as a formula later?
Why a CSV value can behave differently in a spreadsheet

Build a test that matches how your team really works

Test a representative export in a controlled environment, using records that resemble the fields and data sources in real use. Add benign, detectable values such as =1+1, +1+1, -1+1, and @SUM(1,1) to fields that can be edited or imported. These examples can reveal whether the spreadsheet treats a value as a formula without relying on harmful actions.

Include relevant leading control characters, such as a tab, carriage return, or line feed, and locale-dependent full-width variants where they apply. Also test separators and quotes: depending on the export’s delimiter and quoting, a value may shift content into a new cell, leaving a formula-like prefix at the start of that cell.

First inspect the exported CSV as raw text. Confirm what characters and cell boundaries the export actually contains. Then open it using the spreadsheet applications and the opening method your staff use. A computed result in place of the literal value, or a formula shown in the formula bar, indicates formula interpretation.

  • Record the application used, how the file was opened, and any locale settings that could affect parsing.
  • Test each export path and spreadsheet workflow that matters to your team rather than assuming one result covers them all.
  • If staff save, close, and reopen CSV files, include that sequence in the test. A value that appears safe on first open may not remain so after a spreadsheet rewrites the file.
  • Keep the test data harmless and controlled; avoid values intended to execute commands or contact external systems.
Build a test that matches how your team really works

Handle exports as untrusted until you have checked them

Treat CSVs containing user-supplied or imported fields as untrusted input, even when the export comes from a business application your team normally uses. The application may be faithfully exporting text; the spreadsheet program that opens it determines whether some of that text is interpreted as a formula.

Where practical, limit automatic opening and ask staff to use a deliberate import or opening workflow that treats relevant fields as text. The available controls vary by spreadsheet program, so confirm the chosen method with your own test file. Do not assume that a particular import setting is available or behaves the same in every tool.

If your organization transforms values before exporting or sharing a file, document exactly what transformation is applied and test it against the spreadsheet tools and downstream uses in scope. A workaround is not a universal guarantee: CSV quoting, a leading apostrophe, or another prefix can behave differently across applications, and some transformations alter the data.

  • Limit who can generate and distribute exports when the data or destination warrants it.
  • Tell recipients when an export contains user-supplied or externally sourced text, and give them the approved handling steps.
  • Keep an unmodified test copy so that you can compare the raw export with any transformed version.
  • Do not treat ordinary CSV quoting as a security control without testing the complete workflow.

Choose mitigations with their trade-offs in mind

There is no single CSV transformation that is safe for every spreadsheet application and downstream consumer. A method that works when a file is first opened may behave differently after it is saved and reopened. A method that changes spreadsheet interpretation may also change the literal data that another system receives.

For each mitigation you consider, test at least the formula-like prefixes relevant to your data, the export’s separators and quoting, and the spreadsheet workflows staff actually use. Then check whether the output remains usable for its other purposes, such as programmatic import or reporting.

If you cannot establish a reliable transformation for all relevant workflows, prefer a controlled opening process and communicate its limitations rather than describing the CSV as universally safe.

  • Test the first open and any save, close, and reopen steps.
  • Check whether a proposed prefix or escaping method remains in the cell as data and whether that affects downstream imports.
  • Keep the original export format and the transformed copy distinguishable so recipients know which handling has been applied.
  • State which applications and workflows were tested; do not generalize beyond that scope.

Make export handling a repeatable staff procedure

A small procedure makes testing and day-to-day handling easier to repeat. Document who can trigger each export and who is likely to open or receive it. Consider whether the file is shared externally and whether people use its contents to make decisions; those details help determine how cautious the process needs to be.

Assign an owner for the test record and its results. Retest when the application, export format, data sources, or spreadsheet workflow changes, and preserve the reproduction steps and observed behavior. That record should make clear which input was used, how the export was generated, which program opened it, and what the program displayed.

  • List the export, its user-controlled or imported fields, and the people who generate, open, and receive it.
  • Keep a controlled test record with harmless formula-like values and relevant separator or quote cases.
  • Record the raw-file observation, spreadsheet application and opening method, locale where relevant, and whether a formula was evaluated.
  • Document the approved handling method and its tested scope, including any known data changes or downstream limitations.
  • Retest after a change to the application, export format, incoming data, or staff workflow.

Frequently asked questions

Is every CSV export unsafe to open?

No. CSV is text, but spreadsheet software may interpret some cell contents as formulas. Check whether the export contains untrusted values and test how the spreadsheet tools in your workflow handle them.

Which fields should we test first?

Start with fields that users or external systems can supply, such as profile details, comments, ticket subjects, notes, form submissions, and imported records. Include the export paths staff actually use.

Is putting quotes around every CSV value enough?

Not as a universal guarantee. Spreadsheet applications can handle and rewrite CSVs differently, and quoting may not remain protective after saving and reopening. Test the full workflow and any downstream use.

What should count as a failed test?

Treat a computed result instead of the literal test value, or a formula visible in the formula bar, as evidence that the spreadsheet interpreted the cell as a formula. Also check whether separators or quotes created a new cell that begins with a formula-like value.

When should we repeat the test?

Retest after changes to the application, export format, data sources, or spreadsheet-handling workflow. Keep the reproduction steps and observed behavior so the next check can use the same conditions.

Sources and further reading 3