CVE-2020-7704 (published 2020-08-17T17:15Z)

The package linux-cmdline before 1.0.1 are vulnerable to Prototype Pollution via the constructor.

Severity: HIGH
CVSS v2 base score: 7.5 (AV:N/AC:L/Au:N/C:P/I:P/A:P)
CVSS v3 base score: 9.8, CRITICAL (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)

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/piranna/linux-cmdline
commit_details: repo_url: https://github.com/piranna/linux-cmdline
author: Jesús Leganés-Combarro 'piranna
author_date: 2020-08-15 01:41:49+02:00
msg: [fix] Don't pollute prototype
repository: repo_url: https://github.com/piranna/linux-cmdline
repo_name: piranna/linux-cmdline
description: Parser for the Linux kernel command line arguments
repo_language: JavaScript
owner: piranna
file_changes: filename: index.js
change_type: ModificationType.MODIFY
diff: @@ -5,17 +5,6 @@ function reducer(result, arg)
   // Get key node
   const keypath = arg.shift().split('.')
 
-  let key = keypath.shift()
-  let node = result
-
-  while(keypath.length)
-  {
-    node[key] = node[key] || {}
-    node = node[key]
-
-    key = keypath.shift()
-  }
-
   // Get value
   let val = true
   if(arg.length)
@@ -24,8 +13,29 @@ function reducer(result, arg)
     if(val.length === 1) val = val[0]
   }
 
+  let key = keypath.shift()
+
+  if(!keypath.length) return {...result, [key]: val}
+
+  if(!result.hasOwnProperty(key)) result = {...result, [key]: {}}
+
+  let newKey
+  let newNode
+  let node = result
+
+  while(true)
+  {
+    newKey = keypath.shift()
+    newNode = node[key]
+
+    if(!keypath.length) break
+
+    node = node[key] = {...newNode, [newKey]: newNode[newKey] || {}}
+    key = newKey
+  }
+
   // Store value
-  node[key] = val
+  node[key] = {...newNode, [newKey]: val}
 
   return result
 }

programming_language: CoffeeScript
filename: test.js
change_type: ModificationType.MODIFY
diff: @@ -19,3 +19,18 @@ const expected =
 const result = linuxCmdline(cmdline)
 
 deepStrictEqual(result, expected)
+
+
+// Don't pollute prototype
+const result2 = linuxCmdline('__proto__.polluted=foo')
+const expected2 =
+{
+  ['__proto__']:
+  {
+    polluted: 'foo'
+  }
+}
+
+deepStrictEqual(result2, expected2)
+
+deepStrictEqual({}.__proto__.polluted, undefined)

programming_language: CoffeeScript