CVE-2021-25915 (published 2021-03-09T15:15Z)

Prototype pollution vulnerability in 'changeset' versions 0.0.1 through 0.2.5 allows an 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/eugeneware/changeset
commit_details: repo_url: https://github.com/eugeneware/changeset
author: Eugene Ware
author_date: 2021-03-05 15:54:18+11:00
msg: Fix against prototype pollution
repository: repo_url: https://github.com/eugeneware/changeset
repo_name: eugeneware/changeset
description: Library to diff JSON objects into atomic put and delete operations, and apply change sets to objects. Useful with Levelup/LevelDB object synchronization.
repo_language: JavaScript
owner: eugeneware
file_changes: filename: index.js
change_type: ModificationType.MODIFY
diff: @@ -75,9 +75,9 @@ function apply(changes, target, modify) {
               ptr[prop] = {};
             }
 
-            if (i < len - 1) {
+            if (i < len - 1 && ptr.hasOwnProperty(prop)) {
               ptr = ptr[prop];
-            } else {
+            } else if (prop !== '__proto__') {
               ptr[prop] = ch.value;
             }
           });
@@ -101,7 +101,7 @@ function apply(changes, target, modify) {
             } else {
               if (Array.isArray(ptr)) {
                 ptr.splice(parseInt(prop, 10), 1);
-              } else {
+              } else if (ptr.hasOwnProperty(prop)) {
                 delete ptr[prop];
               }
             }

programming_language: JavaScript
filename: index.js
change_type: ModificationType.MODIFY
diff: @@ -243,4 +243,13 @@ describe('changeset', function () {
     ]);
     done();
   });
+
+  it('should not allow prototype pollution', function(done) {
+    var changeset = [
+      { type: 'put', key: ['__proto__','polluted'], value: 'Yes! Its Polluted'}
+    ];
+    diff.apply(changeset, {}, true);
+    expect({}.polluted).to.not.equal('Yes! Its Polluted');
+    done();
+  })
 });

programming_language: JavaScript