CVE-2020-26256 (published 2020-12-08T22:15Z)

Fast-csv is an npm package for parsing and formatting CSVs or any other delimited value file in node. In fast-cvs before version 4.3.6 there is a possible ReDoS vulnerability (Regular Expression Denial of Service) when using ignoreEmpty option when parsing. This has been patched in `v4.3.6` You will only be affected by this if you use the `ignoreEmpty` parsing option. If you do use this option it is recommended that you upgrade to the latest version `v4.3.6` This vulnerability was found using a CodeQL query which identified `EMPTY_ROW_REGEXP` regular expression as vulnerable.

Severity: LOW
CVSS v2 base score: 3.5 (AV:N/AC:M/Au:S/C:N/I:N/A:P)
CVSS v3 base score: 6.5, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H)

Weakness information:
cwe_id: CWE-400
cwe_name: Uncontrolled Resource Consumption
description: The product does not properly control the allocation and maintenance of a limited resource, thereby enabling an actor to influence the amount of resources consumed, eventually leading to the exhaustion of available resources.
extended_description: 
            Limited resources include memory, file system storage, database connection pool entries, and CPU. If an attacker can trigger the allocation of these limited resources, but the number or size of the resources is not controlled, then the attacker could cause a denial of service that consumes all available resources. This would prevent valid users from accessing the product, and it could potentially have an impact on the surrounding environment. For example, a memory exhaustion attack against an application could slow down the application as well as its host operating system.
            There are at least three distinct scenarios which can commonly lead to resource exhaustion:
               
                  Lack of throttling for the number of allocated resources
                  Losing all references to a resource before reaching the shutdown stage
                  Not closing/returning a resource after processing
               
            Resource exhaustion problems are often result due to an incorrect implementation of the following situations:
               
                  Error conditions and other exceptional circumstances.
                  Confusion over which part of the program is responsible for releasing the resource.
               
         
         

Fix information:
repo_url: https://github.com/C2FO/fast-csv
commit_details: repo_url: https://github.com/C2FO/fast-csv
author: doug-martin
author_date: 2020-12-03 08:33:00-07:00
msg: fix: Simplify empty row check by removing complex regex
repository: repo_url: https://github.com/C2FO/fast-csv
repo_name: C2FO/fast-csv
description: CSV parser and formatter for node
repo_language: TypeScript
owner: C2FO
file_changes: filename: issue540.spec.ts
change_type: ModificationType.ADD
diff: @@ -0,0 +1,33 @@
+import { EOL } from 'os';
+import { parseString, RowMap, RowArray } from '../../src';
+
+describe('Issue #540 - https://github.com/C2FO/fast-csv/issues/540', () => {
+    const CSV_CONTENT = [
+        ' , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , -',
+    ].join(EOL);
+
+    const expectedRows = [
+        [
+            ' , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,' +
+                ' , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,' +
+                ' , , , , , , , , , , , , , , -',
+        ],
+    ];
+
+    it('allow transforming to any object shape', () => {
+        return new Promise((res, rej) => {
+            const invalid: RowArray[] = [];
+            const rows: RowMap[] = [];
+            parseString(CSV_CONTENT, { ignoreEmpty: true, delimiter: '\t' })
+                .on('data-invalid', (row: RowArray) => invalid.push(row))
+                .on('data', (r) => rows.push(r))
+                .on('error', rej)
+                .on('end', (count: number) => {
+                    expect(rows).toEqual(expectedRows);
+                    expect(invalid).toHaveLength(0);
+                    expect(count).toBe(expectedRows.length + invalid.length);
+                    res();
+                });
+        });
+    });
+});

programming_language: SQL
filename: Parser.ts
change_type: ModificationType.MODIFY
diff: @@ -4,8 +4,6 @@ import { ParserOptions } from '../ParserOptions';
 import { RowArray } from '../types';
 import { Token } from './Token';
 
-const EMPTY_ROW_REGEXP = /^\s*(?:''|"")?\s*(?:,\s*(?:''|"")?\s*)*$/;
-
 export interface ParseResult {
     line: string;
     rows: string[][];
@@ -79,7 +77,7 @@ export class Parser {
         if (row === null) {
             return false;
         }
-        if (this.parserOptions.ignoreEmpty && EMPTY_ROW_REGEXP.test(row.join(''))) {
+        if (this.parserOptions.ignoreEmpty && RowParser.isEmptyRow(row)) {
             return true;
         }
         rows.push(row);

programming_language: TypeScript
filename: RowParser.ts
change_type: ModificationType.MODIFY
diff: @@ -4,7 +4,13 @@ import { ParserOptions } from '../ParserOptions';
 import { RowArray } from '../types';
 import { MaybeToken, Token } from './Token';
 
+const EMPTY_STRING = '';
+
 export class RowParser {
+    static isEmptyRow(row: RowArray): boolean {
+        return row.join(EMPTY_STRING).replace(/\s+/g, EMPTY_STRING) === EMPTY_STRING;
+    }
+
     private readonly parserOptions: ParserOptions;
 
     private readonly columnParser: ColumnParser;

programming_language: TypeScript