2.10.0 • Published 2 years ago

csv-sanitize v2.10.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Csv-sanitize

A tiny npm package (5.0 kB) that provides a function to sanitize CSV files to prevent CSV Injection attacks as per the recommendations of the Open Web Application Security Project (OWASP).

Ideally you'll use a csv parser (eg papaparse) and this package is just an extra layer of sanitization to prevent the following:

This package its means to prevent aginst:

  1. Cells begining with:
  • Equals to (=)
  • Plus (+)
  • Minus (-)
  • At (@)
  • Tab (0x09)
  • Carriage return (0x0D)
  1. Remove any possible parentheses,
  2. Remove the field separator (eg ',' or ';') and quotation marks (eg ' or "), as a possible starting point for a new hidden cell.

Installation

npm install csv-sanitize
yarn add csv-sanitize

Usage

import { sanitizeCsv } from 'csv-sanitizer';

const originalCsv = `name,email,phone
John Doe,john@example.com,123-456-7890
Jane Doe,jane@example.com,987-654-3210`;

const sanitizedCsv = sanitizeCsv(originalCsv);

console.log(sanitizedCsv);
// Output:
// "name","email","phone"
// "'John Doe","john@example.com","123-456-7890"
// "'Jane Doe","jane@example.com","987-654-3210"

References

OWASP CSV Injection

2.10.0

2 years ago

2.8.0

2 years ago

2.7.0

2 years ago

2.5.0

2 years ago

2.4.0

2 years ago

2.3.0

2 years ago

2.2.0

2 years ago

2.1.0

2 years ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago