diff --git a/packages/core/src/pattern.mjs b/packages/core/src/pattern.mjs index 13b520c6baa..b782362fd78 100644 --- a/packages/core/src/pattern.mjs +++ b/packages/core/src/pattern.mjs @@ -122,7 +122,7 @@ Pattern.prototype.draft = function () { Pattern.prototype.createPartForSet = function (partName, set = 0) { // gotta protect against attacks - if (typeof set === '__proto__') { + if (set === '__proto__') { throw new Error('malicious attempt at altering Object.prototype. Stopping action') } // Create parts diff --git a/packages/core/tests/pattern-draft.test.mjs b/packages/core/tests/pattern-draft.test.mjs index d66459d6780..009f9581dfa 100644 --- a/packages/core/tests/pattern-draft.test.mjs +++ b/packages/core/tests/pattern-draft.test.mjs @@ -33,6 +33,18 @@ describe('Pattern', () => { expect(count).to.equal(2) }) }) + describe('Pattern.createPartForSet()', () => { + it('Should not allow malicious assignment to Object.prototype', () => { + const objProto = Object.prototype + const Pattern = new Design() + const pattern = new Pattern() + + expect(() => pattern.createPartForSet('part', '__proto__')).to.throw( + 'malicious attempt at altering Object.prototype. Stopping action' + ) + expect(objProto).to.equal(Object.prototype) + }) + }) it('Should check whether a part is needed', () => { const partA = { name: 'test.partA',