CVE-2021-25952 (published 2021-07-07T12:15Z)

Prototype pollution vulnerability in ‘just-safe-set’ versions 1.0.0 through 2.2.1 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/angus-c/just
commit_details: repo_url: https://github.com/angus-c/just
author: angus croll
author_date: 2021-05-08 12:44:36-07:00
msg: add proto check (#267)
repository: repo_url: https://github.com/angus-c/just
repo_name: angus-c/just
description: A library of dependency-free JavaScript utilities that do just one thing.
repo_language: JavaScript
owner: angus-c
file_changes: filename: index.js
change_type: ModificationType.MODIFY
diff: @@ -34,8 +34,10 @@ function set(obj, props, value) {
   if (!lastProp) {
     return false;
   }
+  prototypeCheck(lastProp);
   var thisProp;
   while ((thisProp = props.shift())) {
+    prototypeCheck(thisProp);
     if (typeof obj[thisProp] == 'undefined') {
       obj[thisProp] = {};
     }
@@ -47,3 +49,9 @@ function set(obj, props, value) {
   obj[lastProp] = value;
   return true;
 }
+
+function prototypeCheck(prop) {
+  if (prop === '__proto__' || prop === 'constructor' || prop === 'prototype') {
+    throw new Error('setting of prototype values not supported');
+  }
+}

programming_language: JavaScript
filename: package.json
change_type: ModificationType.MODIFY
diff: @@ -1,6 +1,6 @@
 {
   "name": "just-safe-set",
-  "version": "2.2.1",
+  "version": "2.2.2",
   "description": "set value at property, create intermediate properties if necessary",
   "main": "index.js",
   "types": "index.d.ts",

programming_language: JavaScript
filename: index.js
change_type: ModificationType.MODIFY
diff: @@ -66,6 +66,27 @@ test("doesn't interrupt property chain, using array arg", function(t) {
   t.end();
 });
 
+test("doesn't support setting of prototype (and related) values", function(t) {
+  t.plan(4);
+  t.throws(function() {
+    var obj1 = {a: {}};
+    set(obj1, '__proto__.x', function malice() {});
+  });
+  t.throws(function() {
+    var obj1 = {a: {}};
+    set(obj1, ['a', 'b', '__proto__'], {toString: 'hehehe'});
+  });
+  t.throws(function() {
+    var obj2 = {a: {}};
+    set(obj2, 'constructor', function FakeConstructor() {});
+  });
+  t.throws(function() {
+    var obj3 = {a: {}};
+    set(obj3, 'prototype.y', 'hahahaha');
+  });
+  t.end();
+});
+
 /* eslint-disable no-undef*/
 if (typeof Symbol === 'function') {
   test('supports symbol prop', function(t) {

programming_language: JavaScript