CVE-2021-23470 (published 2022-02-04T20:15Z)

This affects the package putil-merge before 3.8.0. The merge() function does not check the values passed into the argument. An attacker can supply a malicious value by adjusting the value to include the constructor property. Note: This vulnerability derives from an incomplete fix in https://security.snyk.io/vuln/SNYK-JS-PUTILMERGE-1317077

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/panates/putil-merge
commit_details: repo_url: https://github.com/panates/putil-merge
author: Eray Hanoğlu
author_date: 2022-02-02 16:21:34+03:00
msg: Fixed Prototype Pollution vulnerability (constructor). Thanks to Gill from Snyk Security
repository: repo_url: https://github.com/panates/putil-merge
repo_name: panates/putil-merge
description: Lightweight solution for merging multiple objects into one. Also it supports deep merge
repo_language: JavaScript
owner: panates
file_changes: filename: merge.js
change_type: ModificationType.MODIFY
diff: @@ -33,7 +33,7 @@ function merge(target, source, options = {}) {
   const keys = Object.getOwnPropertyNames(source);
   keys.push(...Object.getOwnPropertySymbols(source));
   for (const key of keys) {
-    if (key === '__proto__')
+    if (key === '__proto__' || key === 'constructor')
       continue;
     if (options.filter && !options.filter(source, key))
       continue;

programming_language: JavaScript
filename: package.json
change_type: ModificationType.MODIFY
diff: @@ -19,9 +19,9 @@
     "object"
   ],
   "devDependencies": {
-    "eslint": "^7.19.0",
+    "eslint": "^8.8.0",
     "eslint-config-google": "^0.14.0",
-    "mocha": "^9.0.2",
+    "mocha": "^9.2.0",
     "nyc": "^15.1.0"
   },
   "engines": {

programming_language: JavaScript
filename: merge.js
change_type: ModificationType.MODIFY
diff: @@ -237,11 +237,18 @@ describe('merge', function() {
     );
   });
 
-  it('should prevent Prototype Pollution vulnerability', function() {
+  it('should prevent Prototype Pollution vulnerability (__proto__)', function() {
     const payload = JSON.parse('{"__proto__":{"polluted":"Yes! Its Polluted"}}');
     const obj = {};
     merge(obj, payload, {deep: true});
     assert.strictEqual(obj.polluted, undefined);
   });
 
+  it('should prevent Prototype Pollution vulnerability (constructor)', function() {
+    const payload = JSON.parse('{"constructor": {"prototype": {"polluted": "yes"}}}');
+    let obj = {};
+    merge(obj, payload, {deep: true});
+    assert.strictEqual(obj.polluted, undefined);
+  });
+
 });

programming_language: TypeScript