CVE-2021-23558 (published 2022-01-28T22:15Z)

The package bmoor before 0.10.1 are vulnerable to Prototype Pollution due to missing sanitization in set function. **Note:** This vulnerability derives from an incomplete fix in [CVE-2020-7736](https://security.snyk.io/vuln/SNYK-JS-BMOOR-598664)

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/b-heilman/bmoor
commit_details: repo_url: https://github.com/b-heilman/bmoor
author: Brian Heilman
author_date: 2022-01-24 22:54:42-05:00
msg: fix: bug with [__proto__]
repository: repo_url: https://github.com/b-heilman/bmoor
repo_name: b-heilman/bmoor
description: Javascript system for bootstrapping, autoloading, and defining functionality
repo_language: JavaScript
owner: b-heilman
file_changes: filename: package.json
change_type: ModificationType.MODIFY
diff: @@ -1,6 +1,6 @@
 {
   "name": "bmoor",
-  "version": "0.10.0",
+  "version": "0.10.1",
   "author": "Brian Heilman <das.ist.junk@gmail.com>",
   "description": "A basic foundation for other libraries, establishing useful patterbs, and letting them be more.",
   "license": "MIT",
@@ -29,7 +29,8 @@
   },
   "scripts": {
     "lint": "node ./node_modules/eslint/bin/eslint ./src",
-    "test": "npm run prettier && mocha --recursive \"./src/**/*.spec.js\"",
-    "prettier": "npx prettier --write ./src && npm run lint"
+    "test": "mocha --recursive \"./src/**/*.spec.js\"",
+    "prettier": "npx prettier --write ./src",
+    "finalize": "npm run lint && npm run prettier && npm run test"
   }
 }

programming_language: Shell
filename: core.js
change_type: ModificationType.MODIFY
diff: @@ -182,7 +182,7 @@ function set(root, space, value) {
 	val = space.pop();
 
 	for (i = 0, c = space.length; i < c; i++) {
-		nextSpace = space[i];
+		nextSpace = String(space[i]);
 
 		if (
 			nextSpace === '__proto__' ||
@@ -205,6 +205,8 @@ function set(root, space, value) {
 }
 
 function _makeSetter(property, next) {
+	property = String(property);
+
 	if (
 		property === '__proto__' ||
 		property === 'constructor' ||
@@ -265,7 +267,7 @@ function get(root, path) {
 	space = parse(path);
 	if (space.length) {
 		for (i = 0, c = space.length; i < c; i++) {
-			nextSpace = space[i];
+			nextSpace = String(space[i]);
 
 			if (
 				nextSpace === '__proto__' ||
@@ -287,6 +289,8 @@ function get(root, path) {
 }
 
 function _makeGetter(property, next) {
+	property = String(property);
+
 	if (
 		property === '__proto__' ||
 		property === 'constructor' ||

programming_language: JavaScript
filename: core.spec.js
change_type: ModificationType.MODIFY
diff: @@ -92,6 +92,14 @@ describe('Testing object setting/getting', function () {
 
 			expect(t.polluted).to.not.equal(true);
 		});
+
+		it('should not allow __proto__ when in array', function () {
+			var t = {};
+
+			bmoor.set(t, [['__proto__'], 'polluted'], 'polluted');
+
+			expect(t.polluted).to.not.equal('polluted');
+		});
 	});
 
 	describe('::makeSetter', function () {

programming_language: JavaScript