CVE-2019-17592 (published 2019-10-14T20:15Z)

The csv-parse module before 4.4.6 for Node.js is vulnerable to Regular Expression Denial of Service. The __isInt() function contains a malformed regular expression that processes large crafted input very slowly. This is triggered when using the cast option.

Severity: MEDIUM
CVSS v2 base score: 5.0 (AV:N/AC:L/Au:N/C:N/I:N/A:P)
CVSS v3 base score: 7.5, HIGH (CVSS:3.1/AV:N/AC:L/PR:N/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/adaltas/node-csv-parse
commit_details: repo_url: https://github.com/adaltas/node-csv-parse
author: David Worms
author_date: 2019-09-17 22:46:03+02:00
msg: security: remove regexp vulnerable to DOS in cast option, npm report 69742
repository: repo_url: https://github.com/adaltas/node-csv-parse
repo_name: adaltas/node-csv-parse
description: CSV parsing implementing the Node.js `stream.Transform` API
owner: adaltas
file_changes: filename: CHANGELOG.md
change_type: ModificationType.MODIFY
diff: @@ -7,6 +7,10 @@
 * max_comment_size: new option
 * promise: new API module
 
+## Trunk
+
+* security: remove regexp vulnerable to DOS in cast option, npm report 69742
+
 ## Version 4.4.5
 
 * ts: add buffer as allowed type for input, fix #248

programming_language: Markdown
filename: index.js
change_type: ModificationType.MODIFY
diff: @@ -985,21 +985,20 @@ function (_Transform) {
         }
       }
 
-      if (this.__isInt(field) === true) {
-        return [undefined, parseInt(field)];
-      } else if (this.__isFloat(field)) {
+      if (this.__isFloat(field)) {
         return [undefined, parseFloat(field)];
       } else if (this.options.cast_date !== false) {
         return [undefined, this.options.cast_date.call(null, field, context)];
       }
 
       return [undefined, field];
-    }
-  }, {
-    key: "__isInt",
-    value: function __isInt(value) {
-      return /^(\-|\+)?([1-9]+[0-9]*)$/.test(value);
-    }
+    } // Keep it in case we implement the `cast_int` option
+    // __isInt(value){
+    //   // return Number.isInteger(parseInt(value))
+    //   // return !isNaN( parseInt( obj ) );
+    //   return /^(\-|\+)?[1-9][0-9]*$/.test(value)
+    // }
+
   }, {
     key: "__isFloat",
     value: function __isFloat(value) {

programming_language: JavaScript
filename: index.js
change_type: ModificationType.MODIFY
diff: @@ -747,18 +747,19 @@ class Parser extends Transform {
         return [err]
       }
     }
-    if(this.__isInt(field) === true){
-      return [undefined, parseInt(field)]
-    }else if(this.__isFloat(field)){
+    if(this.__isFloat(field)){
       return [undefined, parseFloat(field)]
     }else if(this.options.cast_date !== false){
       return [undefined, this.options.cast_date.call(null, field, context)]
     }
     return [undefined, field]
   }
-  __isInt(value){
-    return /^(\-|\+)?([1-9]+[0-9]*)$/.test(value)
-  }
+  // Keep it in case we implement the `cast_int` option
+  // __isInt(value){
+  //   // return Number.isInteger(parseInt(value))
+  //   // return !isNaN( parseInt( obj ) );
+  //   return /^(\-|\+)?[1-9][0-9]*$/.test(value)
+  // }
   __isFloat(value){
     return (value - parseFloat( value ) + 1) >= 0 // Borrowed from jquery
   }

programming_language: JavaScript
filename: option.cast.coffee
change_type: ModificationType.MODIFY
diff: @@ -31,8 +31,14 @@ describe 'Option `cast`', ->
       parser.end()
 
     it 'ints', (next) ->
-      parse '123a,123,0123,', cast: true, (err, data) ->
-        data.should.eql [ ['123a', 123, 123, ''] ]
+      parse '123a,123,+123,-123,0123,+0123,-0123,', cast: true, (err, data) ->
+        data.should.eql [ ['123a', 123, 123, -123, 123, 123, -123, ''] ]
+        next()
+
+    it 'ints isnt exposed to DOS vulnerabilities, npm security issue 69742', (next) ->
+      data = Array.from( length: 3000000 ).map( (x) -> '1' ).join('') + '!'
+      parse data, cast: true, (err, data) ->
+        data[0][0].length.should.eql 3000001
         next()
 
     it 'float', (next) ->
@@ -54,11 +60,11 @@ describe 'Option `cast`', ->
       , (err, records) ->
         records.should.eql [
           [ '2000-01-01T05:00:00.000Z', {
-            column: 1, empty_lines: 0, header: false, index: 1, 
+            column: 1, empty_lines: 0, header: false, index: 1,
             invalid_field_length: 0, lines: 1, quoting: false, records: 0
           } ]
           [ '2050-11-27T05:00:00.000Z', {
-            column: 1, empty_lines: 0, header: false, index: 1, 
+            column: 1, empty_lines: 0, header: false, index: 1,
             invalid_field_length: 0, lines: 2, quoting: false, records: 1
           } ]
         ] unless err

programming_language: CoffeeScript