CVE-2020-7736 (JavaScript, published 2020-10-02T10:15Z)
Description: value: The package bmoor before 0.8.12 are vulnerable to Prototype Pollution via the set function.
Severity: HIGH (CVSS v3 base score: 9.8)
Weakness: CWE-1321 \u2014 Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution')
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.
Repository: https://github.com/b-heilman/bmoor
Files changed:
package.json
src/core.js
src/core.spec.js
src/object.spec.js
Commit message: fix: prototype pollution


Vulnerable code:
  "version": "0.8.11",
	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);
	});
	it('should have get working with empty strings', function(){
		var t = {
				eins : 1,
				zwei: {
					drei: 3
				}
			};
		expect( bmoor.get(t,'') ).to.equal(t);
	});
	it('should have makeGetter working', function(){
		var t = {
				eins : 1,
				zwei: {
					drei: 3
				}
			},
			f1 = bmoor.makeGetter('eins'),
			f2 = bmoor.makeGetter('zwei.drei');
		expect( f1(t) ).to.equal(1);
		expect( f2(t) ).to.equal(3);
	it('should have makeGetter working with empty strings', function(){
		var t = {
				eins : 1,
				zwei: {
					drei: 3
				}
			},
			f1 = bmoor.makeGetter('');
		expect( f1(t) ).to.equal(t);
	});
	it('should have set 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 have makeSetter working', function(){
		var t = {},
			f1 = bmoor.makeSetter('eins'),
			f2 = bmoor.makeSetter('zwei.drei');
		f1(t,1);
		f2(t,3);
		expect( t.eins ).to.equal(1);
		expect( t.zwei.drei ).to.equal(3);
	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 = {
			},
			explode = bmoor.object.makeExploder( Object.keys(t) );
		expect(explode(t))
		.to.deep.equal({
			eins: {
				zwei: 12,
				drei: 13
			},
			fier: 4
	describe(':: implode', function(){
	});
	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
});

Fixed code:
  "version": "0.8.12",
		if (nextSpace === '__proto__'){
			return null;
		}

	if (property === '__proto__'){
		throw new Error('unable to access __proto__');
	}

			if (nextSpace === '__proto__'){
				return null;
			}

	if (property === '__proto__'){
		throw new Error('unable to access __proto__');
	}

	describe('::get', function(){
		it('should be 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);
		});
		it('should be working with empty strings', function(){
			var t = {
					eins : 1,
					zwei: {
						drei: 3
					}
				};
			expect( bmoor.get(t,'') ).to.equal(t);
		});
		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');
			expect( f1(t) ).to.equal(1);
			expect( f2(t) ).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 work with empty strings', function(){
			var t = {
					eins : 1,
					zwei: {
						drei: 3
					}
				},
				f1 = bmoor.makeGetter('');

			expect( f1(t) ).to.equal(t);
		});
	});	
	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);
		});
	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);
			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);
		});
	describe('::explode', function(){
		it('should operate explode correctly', function(){
			var 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
			});
	describe('::implode', function(){
		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
			});
});