CVE-2022-24279 (published 2022-04-15T20:15Z)

The package madlib-object-utils before 0.1.8 are vulnerable to Prototype Pollution via the setValue method, as it allows an attacker to merge object prototypes into it. *Note:* This vulnerability derives from an incomplete fix of [CVE-2020-7701](https://security.snyk.io/vuln/SNYK-JS-MADLIBOBJECTUTILS-598676)

Severity: MEDIUM
CVSS v2 base score: 5.0 (AV:N/AC:L/Au:N/C:N/I:P/A:N)
CVSS v3 base score: 7.5, HIGH (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/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/Qwerios/madlib-object-utils
commit_details: repo_url: https://github.com/Qwerios/madlib-object-utils
author: Mark Doeswijk
author_date: 2022-03-07 10:27:07+01:00
msg: fix(set-value): prototype pollution
repository: repo_url: https://github.com/Qwerios/madlib-object-utils
repo_name: Qwerios/madlib-object-utils
description: A small set of utility functions for working with objects
repo_language: CoffeeScript
owner: Qwerios
file_changes: filename: utils.js
change_type: ModificationType.MODIFY
diff: @@ -30,12 +30,6 @@
       aPath = ("" + path).split(".");
       value = object;
       key = aPath.shift();
-      if (key === 'constructor' && typeof object[key] === 'function') {
-        return;
-      }
-      if (key === '__proto__') {
-        return;
-      }
       if (aPath.length === 0) {
         value = value[key.replace("%2E", ".")];
         if (value == null) {
@@ -64,17 +58,14 @@
       aPath = ("" + path).split(".");
       value = object;
       key = aPath.shift();
-      if (key === 'constructor' && typeof object[key] === 'function') {
-        return object;
-      }
-      if (key === '__proto__') {
-        return object;
-      }
       while (key) {
         key = key.replace("%2E", ".");
         if (value[key] == null) {
           value[key] = {};
         }
+        if (!value.hasOwnProperty(key)) {
+          return;
+        }
         if (aPath.length === 0) {
           if (defaultValue != null) {
             value[key] = defaultValue;

programming_language: JavaScript
filename: utils.coffee
change_type: ModificationType.MODIFY
diff: @@ -31,11 +31,6 @@
         value = object
         key   = aPath.shift()
 
-        if key is 'constructor' and typeof object[key] is 'function'
-            return
-        if key is '__proto__'
-            return
-
         if aPath.length is 0
             # This is only a 1 deep check
             #
@@ -60,11 +55,6 @@
         value = object
         key   = aPath.shift()
 
-        if key is 'constructor' and typeof object[key] is 'function'
-            return object
-        if key is '__proto__'
-            return object
-
         while key
             key = key.replace( "%2E", "." )
 
@@ -73,6 +63,9 @@
             if not value[ key ]?
                 value[ key ] = {}
 
+            if not value.hasOwnProperty(key)
+                return
+
             if aPath.length is 0
                 # Assign the default value to the newly created key if supplied
                 #

programming_language: CoffeeScript
filename: prototype-pollution.coffee
change_type: ModificationType.MODIFY
diff: @@ -5,8 +5,10 @@ describe( "Prototype pollution", () ->
     describe( "#setValue()", () ->
         it( "Should not pollute value", () ->
             objectUtils.setValue( '__proto__.polluted', {}, true )
-
             chai.expect( global.polluted ).to.eql( undefined )
+
+            objectUtils.setValue('this.constructor.prototype.polluted', {}, 'yes');
+            chai.expect( {}.polluted ).to.eql( undefined )
         )
     )
 )

programming_language: CoffeeScript