CVE-2022-24802 (published 2022-04-01T00:15Z)

deepmerge-ts is a typescript library providing functionality to deep merging of javascript objects. deepmerge-ts is vulnerable to Prototype Pollution via file deepmerge.ts, function defaultMergeRecords(). This issue has been patched in version 4.0.2. There are no known workarounds for this issue.

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/RebeccaStevens/deepmerge-ts
commit_details: repo_url: https://github.com/RebeccaStevens/deepmerge-ts
author: Rebecca Stevens
author_date: 2022-03-31 20:49:31+13:00
msg: fix: protect against prototype pollution
repository: repo_url: https://github.com/RebeccaStevens/deepmerge-ts
repo_name: RebeccaStevens/deepmerge-ts
description: Deeply merge 2 or more objects respecting type information.
repo_language: TypeScript
owner: RebeccaStevens
file_changes: filename: deepmerge.ts
change_type: ModificationType.MODIFY
diff: @@ -438,7 +438,16 @@ function defaultMergeRecords<
       continue;
     }
 
-    result[key] = propertyResult;
+    if (key === "__proto__") {
+      Object.defineProperty(result, key, {
+        value: propertyResult,
+        configurable: true,
+        enumerable: true,
+        writable: true,
+      });
+    } else {
+      result[key] = propertyResult;
+    }
   }
 
   /* eslint-enable functional/no-loop-statement, functional/no-conditional-statement */

programming_language: Scala
filename: deepmerge.test.ts
change_type: ModificationType.MODIFY
diff: @@ -539,3 +539,19 @@ test(`merging objects with null prototype`, (t) => {
 
   t.deepEqual(merged, expected);
 });
+
+test("prototype pollution", (t) => {
+  const payload = '{"__proto__":{"a0":true}}';
+
+  const x: any = JSON.parse(payload);
+  const y: any = {};
+
+  const merged: any = deepmerge(x, y);
+
+  t.deepEqual(JSON.stringify(merged), payload);
+
+  t.not(({} as any).a0, true, "Safe POJO");
+  t.not(x.a0, true, "Safe x input");
+  t.not(y.a0, true, "Safe y input");
+  t.not(merged.a0, true, "Safe output");
+});

programming_language: TypeScript
repo_url: https://github.com/RebeccaStevens/deepmerge-ts
commit_details: repo_url: https://github.com/RebeccaStevens/deepmerge-ts
author: Rebecca Stevens
author_date: 2022-03-31 21:01:53+13:00
msg: Merge pull request #86 from RebeccaStevens/security/prototype-pollution
repository: repo_url: https://github.com/RebeccaStevens/deepmerge-ts
repo_name: RebeccaStevens/deepmerge-ts
description: Deeply merge 2 or more objects respecting type information.
repo_language: TypeScript
owner: RebeccaStevens