CVE-2020-28270 (published 2020-11-12T18:15Z)

Prototype pollution vulnerability in 'object-hierarchy-access' versions 0.2.0 through 0.32.0 allows 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/mjpclab/object-hierarchy-access
commit_details: repo_url: https://github.com/mjpclab/object-hierarchy-access
author: marjune
author_date: 2020-11-07 16:43:42+08:00
msg: fix(setup): prevent assigning value to `__proto__`

Assigning value to `__proto__` polutes `Object.prototype`.

Reported by Daniel Elkabes from White Source Software.
repository: repo_url: https://github.com/mjpclab/object-hierarchy-access
repo_name: mjpclab/object-hierarchy-access
description: Get/Set value from/to JS object hierarchy properties
repo_language: JavaScript
owner: mjpclab
file_changes: filename: setup.js
change_type: ModificationType.MODIFY
diff: @@ -1,12 +1,17 @@
 import { normalizeDescriptor } from './utility/setup';
 import { getNonEmptyPropName } from './utility/common';
+const propProto = '__proto__';
 function generate(target, hierarchies, forceOverride) {
     let current = target;
     hierarchies.forEach(info => {
         const descriptor = normalizeDescriptor(info);
         const { value, type, create, override, created, skipped, got } = descriptor;
         const name = getNonEmptyPropName(current, descriptor);
-        if (forceOverride || override || !current[name] || typeof current[name] !== 'object') {
+        if (forceOverride ||
+            override ||
+            !current[name] ||
+            typeof current[name] !== 'object' ||
+            (name === propProto && current[name] === Object.prototype)) {
             const obj = value ? value :
                 type ? new type() :
                     create ? create.call(current, current, name) :

programming_language: TypeScript
filename: setup.ts
change_type: ModificationType.MODIFY
diff: @@ -2,6 +2,8 @@ import type {SetupPropParam} from './type';
 import {normalizeDescriptor} from './utility/setup';
 import {getNonEmptyPropName} from './utility/common';
 
+const propProto = '__proto__';
+
 function generate(
 	target: any,
 	hierarchies: SetupPropParam[],
@@ -13,7 +15,13 @@ function generate(
 		const {value, type, create, override, created, skipped, got} = descriptor;
 
 		const name = getNonEmptyPropName(current, descriptor);
-		if (forceOverride || override || !current[name] || typeof current[name] !== 'object') {
+		if (
+			forceOverride ||
+			override ||
+			!current[name] ||
+			typeof current[name] !== 'object' ||
+			(name === propProto && current[name] === Object.prototype)
+		) {
 			const obj = value ? value :
 				type ? new type() :
 					create ? create.call(current, current, name) :

programming_language: TypeScript
filename: 7-no-proto-polution.js
change_type: ModificationType.ADD
diff: @@ -0,0 +1,9 @@
+const assert = require('assert').strict;
+const {set} = require('../../');
+
+const obj1 = {};
+const obj2 = {};
+set(obj1, '__proto__', 'admin', true);
+assert.notEqual(obj1.__proto__, Object.prototype);
+assert.equal(obj1.__proto__.admin, true);
+assert.strictEqual(obj2.admin, undefined);

programming_language: JavaScript
filename: index.js
change_type: ModificationType.MODIFY
diff: @@ -4,3 +4,4 @@ require('./3-symbol-property');
 require('./4-array-params');
 require('./5-array-value');
 require('./6-option-params');
+require('./7-no-proto-polution');

programming_language: JavaScript