CVE-2020-7600 (published 2020-03-12T23:15Z)

querymen prior to 2.1.4 allows modification of object properties. The parameters of exported function handler(type, name, fn) can be controlled by users without any sanitization. This could be abused for Prototype Pollution attacks.

Severity: MEDIUM
CVSS v2 base score: 5.0 (AV:N/AC:L/Au:N/C:N/I:P/A:N)
CVSS v3 base score: 5.3, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N)

Weakness information:
cwe_id: CWE-1321
cwe_name: Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution')
description: The product receives input from an upstream component that specifies attributes that are to be initialized or updated in an object, but it does not properly control modifications of attributes of the object prototype.
extended_description: 
				By adding or modifying attributes of an object prototype, it is possible to create attributes that exist on every object, or replace critical attributes with malicious ones. This can be problematic if the product depends on existence or non-existence of certain attributes, or uses pre-defined attributes of object prototype (such as hasOwnProperty, toString or valueOf).
				This weakness is usually exploited by using a special attribute of objects called proto,  constructor or prototype. Such attributes give access to the object prototype. This weakness is often found in code that assigns object attributes based on user input, or merges or clones objects recursively.
			
			

Fix information:
repo_url: https://github.com/diegohaz/querymen
commit_details: repo_url: https://github.com/diegohaz/querymen
author: Haz
author_date: 2020-03-12 14:17:17-03:00
msg: Fix prototype pollution vulnerability (#77)

* Fix prototype pollution vulnerability

* Fix test
repository: repo_url: https://github.com/diegohaz/querymen
repo_name: diegohaz/querymen
description: Querystring parser middleware for MongoDB, Express and Nodejs (MEN)
repo_language: JavaScript
owner: diegohaz
file_changes: filename: .travis.yml
change_type: ModificationType.MODIFY
diff: @@ -1,7 +1,6 @@
 language: node_js
 services: mongodb
 node_js:
-  - v5
-  - v4
+  - v6
 after_script:
   - 'npm run coveralls'

programming_language: SQL
filename: index.js
change_type: ModificationType.MODIFY
diff: @@ -19,6 +19,14 @@ export let handlers = {
  * @param {Function} [fn] - Set the handler method.
  */
 export function handler (type, name, fn) {
+  if (
+    type === 'constructor' ||
+    type === '__proto__' ||
+    name === 'constructor' ||
+    name === '__proto__'
+  ) {
+    return
+  }
   if (arguments.length > 2) {
     handlers[type][name] = fn
   }

programming_language: JavaScript
filename: index.js
change_type: ModificationType.MODIFY
diff: @@ -42,6 +42,21 @@ const route = (...args) => {
   return app
 }
 
+test('Prototype pollution', (t) => {
+  const { toString } = {}
+
+  querymen.handler('__proto__', 'toString', 'JHU')
+  t.ok({}.toString === toString, 'should not be vulnerable to prototype pollution')
+
+  querymen.handler('formatters', '__proto__', { toString: 'JHU' })
+  t.ok({}.toString === toString, 'should not be vulnerable to prototype pollution')
+
+  querymen.handler('validators', '__proto__', { toString: 'JHU' })
+  t.ok({}.toString === toString, 'should not be vulnerable to prototype pollution')
+
+  t.end()
+})
+
 test('Querymen handler', (t) => {
   t.notOk(querymen.parser('testParser'), 'should not get nonexistent parser')
   t.notOk(querymen.formatter('testFormatter'), 'should not get nonexistent formatter')

programming_language: CoffeeScript
filename: querymen-schema.js
change_type: ModificationType.MODIFY
diff: @@ -29,7 +29,7 @@ test('QuerymenSchema add', (t) => {
   t.same(add('123,456', [Number]), [123, 456], 'should add a param with type option number array')
   t.same(add('123,0', [Boolean]), [true, false], 'should add a param with type option boolean array')
   t.same(add('2016,2017', [Date]), [new Date('2016'), new Date('2017')], 'should add a param with type option date array')
-  t.same(add('123,456', [RegExp]), [/123/i, /123/i], 'should add a param with type option regexp array')
+  t.same(add('123,456', [RegExp]), [/123/i, /456/i], 'should add a param with type option regexp array')
   t.end()
 })
 

programming_language: JavaScript