CVE-2020-7736 (published 2020-10-02T10:15Z)

The package bmoor before 0.8.12 are vulnerable to Prototype Pollution via the set function.

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: 2020-09-17 00:24:17-04:00
msg: fix: prototype pollution
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.8.11",
+  "version": "0.8.12",
   "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",

programming_language: JavaScript
filename: core.js
change_type: ModificationType.MODIFY
diff: @@ -184,6 +184,10 @@ function set( root, space, value ){
 	for( i = 0, c = space.length; i < c; i++ ){
 		nextSpace = space[ i ];
 			
+		if (nextSpace === '__proto__'){
+			return null;
+		}
+
 		if ( isUndefined(curSpace[nextSpace]) ){
 			curSpace[ nextSpace ] = {};
 		}
@@ -197,6 +201,10 @@ function set( root, space, value ){
 }
 
 function _makeSetter( property, next ){
+	if (property === '__proto__'){
+		throw new Error('unable to access __proto__');
+	}
+
 	if ( next ){
 		return function setter( ctx, value ){
 			var t = ctx[property];
@@ -250,6 +258,10 @@ function get( root, path ){
 		for( i = 0, c = space.length; i < c; i++ ){
 			nextSpace = space[i];
 				
+			if (nextSpace === '__proto__'){
+				return null;
+			}
+
 			if ( isUndefined(curSpace[nextSpace]) ){
 				return;
 			}
@@ -262,6 +274,10 @@ function get( root, path ){
 }
 
 function _makeGetter( property, next ){
+	if (property === '__proto__'){
+		throw new Error('unable to access __proto__');
+	}
+
 	if (next){
 		return function getter( obj ){
 			try {

programming_language: JavaScript
filename: core.spec.js
change_type: ModificationType.MODIFY
diff: @@ -4,75 +4,127 @@ const {expect} = require('chai');
 const bmoor = require('./index.js');
 
 describe('Testing object setting/getting', function() {
-	it('should have get working', function(){
-		var t = {
-				eins : 1,
-				zwei: {
-					drei: 3
-				}
-			};
 
-		expect( bmoor.get(t,'eins') ).to.equal(1);
-		expect( bmoor.get(t,'zwei.drei') ).to.equal(3);
-	});
+	describe('::get', function(){
+		it('should be working', function(){
+			var t = {
+					eins : 1,
+					zwei: {
+						drei: 3
+					}
+				};
 
-	it('should have get working with empty strings', function(){
-		var t = {
-				eins : 1,
-				zwei: {
-					drei: 3
-				}
-			};
+			expect( bmoor.get(t,'eins') ).to.equal(1);
+			expect( bmoor.get(t,'zwei.drei') ).to.equal(3);
+		});
 
-		expect( bmoor.get(t,'') ).to.equal(t);
-	});
+		it('should be working with empty strings', function(){
+			var t = {
+					eins : 1,
+					zwei: {
+						drei: 3
+					}
+				};
 
-	it('should have makeGetter working', function(){
-		var t = {
-				eins : 1,
-				zwei: {
-					drei: 3
-				}
-			},
-			f1 = bmoor.makeGetter('eins'),
-			f2 = bmoor.makeGetter('zwei.drei');
+			expect( bmoor.get(t,'') ).to.equal(t);
+		});
 
-		expect( f1(t) ).to.equal(1);
-		expect( f2(t) ).to.equal(3);
+		it('should not allow __proto__', function(){
+			var t = bmoor.get({}, '__proto__');
+			
+			expect(t)
+			.to.equal(null);
+		});
 	});
+	
+	describe('::makeGetter', function(){
+		it('should be working', function(){
+			var t = {
+					eins : 1,
+					zwei: {
+						drei: 3
+					}
+				},
+				f1 = bmoor.makeGetter('eins'),
+				f2 = bmoor.makeGetter('zwei.drei');
 
-	it('should have makeGetter working with empty strings', function(){
-		var t = {
-				eins : 1,
-				zwei: {
-					drei: 3
-				}
-			},
-			f1 = bmoor.makeGetter('');
+			expect( f1(t) ).to.equal(1);
+			expect( f2(t) ).to.equal(3);
+		});
 
-		expect( f1(t) ).to.equal(t);
-	});
+		it('should fail with __proto__', function(){
+			let failed = false;
 
-	it('should have set working', function(){
-		var t = {};
+			try {
+				bmoor.makeGetter('__proto__.polluted');
+			} catch(ex){
+				failed = true;
+			}
+
+			expect(failed)
+			.to.equal(true);
+		});
 
-		bmoor.set(t,'eins',1);
-		bmoor.set(t,'zwei.drei',3);
+		it('should work with empty strings', function(){
+			var t = {
+					eins : 1,
+					zwei: {
+						drei: 3
+					}
+				},
+				f1 = bmoor.makeGetter('');
+
+			expect( f1(t) ).to.equal(t);
+		});
+	});	
 
-		expect( t.eins ).to.equal(1);
-		expect( t.zwei.drei ).to.equal(3);
+	describe('::set', function(){
+		it('should be working working', function(){
+			var t = {};
+
+			bmoor.set(t,'eins',1);
+			bmoor.set(t,'zwei.drei',3);
+
+			expect( t.eins ).to.equal(1);
+			expect( t.zwei.drei ).to.equal(3);
+		});
+
+		it('should not allow __proto__', function(){
+			var t = {};
+
+			bmoor.set(t,'__proto__.polluted', true);
+			
+			expect( t.polluted )
+			.to.not.equal(true);
+		});
 	});
 
-	it('should have makeSetter working', function(){
-		var t = {},
-			f1 = bmoor.makeSetter('eins'),
-			f2 = bmoor.makeSetter('zwei.drei');
+	describe('::makeSetter', function(){
+		it('should actually work', function(){
+			var t = {},
+				f1 = bmoor.makeSetter('eins'),
+				f2 = bmoor.makeSetter('zwei.drei');
 
-		f1(t,1);
-		f2(t,3);
+			f1(t,1);
+			f2(t,3);
 
-		expect( t.eins ).to.equal(1);
-		expect( t.zwei.drei ).to.equal(3);
+			expect( t.eins ).to.equal(1);
+			expect( t.zwei.drei ).to.equal(3);
+		});
+
+		it('should fail with __proto__', function(){
+			let failed = false;
+
+			try {
+				bmoor.makeGetter('__proto__.polluted');
+			} catch(ex){
+				failed = true;
+			}
+				
+
+			expect(failed)
+			.to.equal(true);
+		});
 	});
 
 	it('should have del working', function(){

programming_language: JavaScript
filename: object.spec.js
change_type: ModificationType.MODIFY
diff: @@ -5,42 +5,44 @@ describe('bmoor.object', function() {
 	
 	const bmoor = require('./index.js');
 
-	it('should operate explode correctly', function(){
-		var t = {
-			'eins.zwei': 12,
-			'eins.drei': 13,
-			'fier': 4
-		};
-
-		expect(bmoor.object.explode(t))
-		.to.deep.equal({
-			eins: {
-				zwei: 12,
-				drei: 13
-			},
-			fier: 4
-		});
-	});
-
-	it('should operate makeExploder correctly', function(){
-		var t = {
+	describe('::explode', function(){
+		it('should operate explode correctly', function(){
+			var t = {
 				'eins.zwei': 12,
 				'eins.drei': 13,
 				'fier': 4
-			},
-			explode = bmoor.object.makeExploder( Object.keys(t) );
+			};
+
+			expect(bmoor.object.explode(t))
+			.to.deep.equal({
+				eins: {
+					zwei: 12,
+					drei: 13
+				},
+				fier: 4
+			});
+		});
+
+		it('should operate makeExploder correctly', function(){
+			var t = {
+					'eins.zwei': 12,
+					'eins.drei': 13,
+					'fier': 4
+				},
+				explode = bmoor.object.makeExploder( Object.keys(t) );
 
-		expect(explode(t))
-		.to.deep.equal({
-			eins: {
-				zwei: 12,
-				drei: 13
-			},
-			fier: 4
+			expect(explode(t))
+			.to.deep.equal({
+				eins: {
+					zwei: 12,
+					drei: 13
+				},
+				fier: 4
+			});
 		});
 	});
 
-	describe(':: implode', function(){
+	describe('::implode', function(){
 		it('should operate correctly', function(){
 			var t = {
 				time: {
@@ -113,32 +115,32 @@ describe('bmoor.object', function() {
 				]
 			});
 		});
-	});
 
-	it('should operate implode correctly - with an ignore', function(){
-		var t = {
-			time: {
-				start: 99,
-				stop: 100
-			},
-			id: 'woot',
-			foo: {
-				bar: {
-					hello: 'world'
+		it('should operate implode correctly - with an ignore', function(){
+			var t = {
+				time: {
+					start: 99,
+					stop: 100
+				},
+				id: 'woot',
+				foo: {
+					bar: {
+						hello: 'world'
+					}
 				}
-			}
-		};
+			};
 
-		expect(bmoor.object.implode(t, {
-			ignore: {
-				time:{
-					start:true
-				},
-				id: true,
-				foo: true
-			}
-		})).to.deep.equal({
-			'time.stop': 100
+			expect(bmoor.object.implode(t, {
+				ignore: {
+					time:{
+						start:true
+					},
+					id: true,
+					foo: true
+				}
+			})).to.deep.equal({
+				'time.stop': 100
+			});
 		});
 	});
 
@@ -177,4 +179,4 @@ describe('bmoor.object', function() {
 			});
 		});
 	});
-});
\ No newline at end of file
+});

programming_language: JavaScript