When an application exports user-controllable data into spreadsheet formats (such as.csv or.xls) without sanitizing inputs, it is referred to as formula injection, CSV injection, or Excel injection. Certain characters (=, +, -, or @) at the start of a cell are treated as formulas by spreadsheet programs like Google Sheets and Microsoft Excel.
An attacker can run undesired commands or payloads if they add formula syntax to fields like name, email, or address and then export and open the data in a spreadsheet program. This gets risky when:
Spreadsheet functions like =HYPERLINK("http://malicious.site") are injected by the attacker.
Alternatively, in older or incorrectly configured environments, malicious scripts such as =CMD|' /C calc'!A0
Example:
When the application admin downloads and opens user data in Excel, the formula executes as a hyperlink — potentially leading to phishing or malware download.
Although Formula Injection may not directly target the web application or server, its true impact is felt by users, frequently those working in internal systems or handling exported data.
What can go wrong is as follows:
The risk is in the degree of trustworthiness of exported spreadsheets. Because employees might not anticipate being compromised, this attack is particularly successful.
Prepend a single quote (') to any cell starting with one of the following characters: =, +, -, or @.
This prevents the spreadsheet application from treating the input as a formula, rendering it as plain text instead.
Use libraries with built-in escaping/sanitization when creating CSV or Excel files. For instance:
Make sure that when entering data, inputs are verified. Inputs that appear suspicious or contain formula characters in fields you didn't intend to use should be rejected or flagged.