CVE-2020-28271 (published 2020-11-12T18:15Z)

Prototype pollution vulnerability in 'deephas' versions 1.0.0 through 1.0.5 allows attacker to cause a denial of service and may lead to remote code execution.

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/sharpred/deepHas
commit_details: repo_url: https://github.com/sharpred/deepHas
author: Paul Ryan
author_date: 2020-10-27 09:44:05+00:00
msg: fix vulnerability reported by whitesource software
repository: repo_url: https://github.com/sharpred/deepHas
repo_name: sharpred/deepHas
description: test for existence of nested object key and optionally return that key
repo_language: JavaScript
owner: sharpred
file_changes: filename: deepHas.js
change_type: ModificationType.MODIFY
diff: @@ -8,7 +8,7 @@ var indexFalse,
     set;
 
 function indexer(set) {
-    return function(obj, i) {
+    return function (obj, i) {
         "use strict";
         try {
             if (obj && i && obj.hasOwnProperty(i)) {
@@ -18,7 +18,7 @@ function indexer(set) {
                 return obj[i];
             }
             return;
-        } catch(ex) {
+        } catch (ex) {
             console.error(ex);
             return;
         }
@@ -31,15 +31,15 @@ indexFalse = indexer(false);
 function reduce(obj, str) {
     "use strict";
     try {
-        if ( typeof str !== "string") {
+        if (typeof str !== "string") {
             return;
         }
-        if ( typeof obj !== "object") {
+        if (typeof obj !== "object") {
             return;
         }
         return str.split('.').reduce(indexFalse, obj);
 
-    } catch(ex) {
+    } catch (ex) {
         console.error(ex);
         return;
     }
@@ -49,21 +49,26 @@ function reduce(obj, str) {
 function add(obj, str, val) {
     "use strict";
     try {
-        if ( typeof str !== "string") {
+        if (typeof str !== "string") {
             return;
         }
-        if ( typeof obj !== "object") {
+        if (str.indexOf('__proto__') != -1) {
+            throw "cannot modify prototype property";
+        }
+        if (typeof obj !== "object") {
             return;
         }
         if (!val) {
             return;
         }
         var items = str.split('.');
+        console.log(str);
         var initial = items.slice(0, items.length - 1);
         var last = items.slice(items.length - 1);
         var test = initial.reduce(indexTrue, obj);
         test[last] = val;
-    } catch(ex) {
+
+    } catch (ex) {
         console.error(ex);
         return;
     }
@@ -73,11 +78,11 @@ function has(target, path) {
     "use strict";
     try {
         var test = reduce(target, path);
-        if ( typeof test !== "undefined") {
+        if (typeof test !== "undefined") {
             return true;
         }
         return false;
-    } catch(ex) {
+    } catch (ex) {
         console.error(ex);
         return;
     }
@@ -87,7 +92,7 @@ function get(target, path) {
     "use strict";
     try {
         return reduce(target, path);
-    } catch(ex) {
+    } catch (ex) {
         console.error(ex);
         return;
     }
@@ -97,7 +102,7 @@ function set(target, path, val) {
     "use strict";
     try {
         return add(target, path, val);
-    } catch(ex) {
+    } catch (ex) {
         console.error(ex);
         return;
     }

programming_language: TypeScript
filename: package-lock.json
change_type: ModificationType.ADD
diff: @@ -0,0 +1,45 @@
+{
+  "name": "deephas",
+  "version": "1.0.5",
+  "lockfileVersion": 1,
+  "requires": true,
+  "dependencies": {
+    "should": {
+      "version": "8.0.1",
+      "resolved": "https://registry.npmjs.org/should/-/should-8.0.1.tgz",
+      "integrity": "sha1-OjpxF9RfKaNnvBKch4owPsHvZAo=",
+      "dev": true,
+      "requires": {
+        "should-equal": "0.5.0",
+        "should-format": "0.3.1",
+        "should-type": "0.2.0"
+      },
+      "dependencies": {
+        "should-equal": {
+          "version": "0.5.0",
+          "resolved": "https://registry.npmjs.org/should-equal/-/should-equal-0.5.0.tgz",
+          "integrity": "sha1-x5fxNfMGf+tp6+zbMGscP+IbPm8=",
+          "dev": true,
+          "requires": {
+            "should-type": "0.2.0"
+          }
+        },
+        "should-format": {
+          "version": "0.3.1",
+          "resolved": "https://registry.npmjs.org/should-format/-/should-format-0.3.1.tgz",
+          "integrity": "sha1-LLt4JGFnCs5CkrKx7EaNuM+Z4zA=",
+          "dev": true,
+          "requires": {
+            "should-type": "0.2.0"
+          }
+        },
+        "should-type": {
+          "version": "0.2.0",
+          "resolved": "https://registry.npmjs.org/should-type/-/should-type-0.2.0.tgz",
+          "integrity": "sha1-ZwfvlVKdmJ3MCY/gdTqx+RNrt/Y=",
+          "dev": true
+        }
+      }
+    }
+  }
+}

programming_language: Scala
filename: package.json
change_type: ModificationType.MODIFY
diff: @@ -1,6 +1,6 @@
 {
   "name": "deephas",
-  "version": "1.0.5",
+  "version": "1.0.6",
   "description": "get, set or test for a value in a javascript object",
   "main": "deepHas.js",
   "scripts": {

programming_language: JavaScript
filename: poc.js
change_type: ModificationType.ADD
diff: @@ -0,0 +1,5 @@
+var dh = require("./deepHas");
+var obj = {};
+console.log(obj.isAdmin);
+dh.set(obj,'__proto__.isAdmin','true');
+console.log(obj.isAdmin);
\ No newline at end of file

programming_language: JavaScript
filename: runTests.sh
change_type: ModificationType.MODIFY
diff: @@ -2,4 +2,5 @@
 node tests/testHas.js
 node tests/testGet.js
 node tests/testExports.js
-node tests/testSet.js
\ No newline at end of file
+node tests/testSet.js
+node tests/testVulnerability.js
\ No newline at end of file

programming_language: Shell
filename: testVulnerability.js
change_type: ModificationType.ADD
diff: @@ -0,0 +1,10 @@
+var dh = require("../deepHas"),
+    should = require("should"),
+    obj;
+
+obj = {};
+
+dh.set(obj,'__proto__.isAdmin',true);
+
+should.not.exist(obj.isAdmin);
+obj.hasOwnProperty('isAdmin').should.equal(false);
\ No newline at end of file

programming_language: JavaScript