|
| 1 | +import { expect } from 'chai'; |
| 2 | +import { extend } from '../../../../src/core/core.js'; |
| 3 | +import { Markup } from '../../../../src/framework/components/element/markup.js'; |
| 4 | + |
| 5 | +describe('Security: Prototype Pollution', function () { |
| 6 | + describe('Markup Parser', function () { |
| 7 | + it('should ignore sensitive keys like __proto__ during merging', function () { |
| 8 | + const symbols = ['[', '_', '_', 'p', 'r', 'o', 't', 'o', '_', '_', ' ', 'p', 'o', 'l', 'l', 'u', 't', 'e', 'd', '=', '"', 't', 'r', 'u', 'e', '"', ']', 'h', 'e', 'l', 'l', 'o']; |
| 9 | + |
| 10 | + // Ensure Object.prototype is clean before test |
| 11 | + expect({}.polluted).to.be.undefined; |
| 12 | + |
| 13 | + try { |
| 14 | + Markup.evaluate(symbols); |
| 15 | + } catch (e) { |
| 16 | + // ignore potential errors during evaluation as we only care about pollution |
| 17 | + } |
| 18 | + |
| 19 | + expect({}.polluted).to.be.undefined; |
| 20 | + }); |
| 21 | + |
| 22 | + it('should ignore constructor and prototype keys', function () { |
| 23 | + const symbols = ['[', 'c', 'o', 'n', 's', 't', 'r', 'u', 'c', 't', 'o', 'r', ']', 't', 'e', 's', 't']; |
| 24 | + |
| 25 | + const results = Markup.evaluate(symbols); |
| 26 | + expect(results.tags).to.not.have.property('constructor'); |
| 27 | + }); |
| 28 | + }); |
| 29 | + |
| 30 | + describe('Core: extend utility', function () { |
| 31 | + it('should protect against prototype pollution', function () { |
| 32 | + const payload = JSON.parse('{"__proto__": {"vulnerable": "yes"}}'); |
| 33 | + const target = {}; |
| 34 | + |
| 35 | + extend(target, payload); |
| 36 | + |
| 37 | + expect({}.vulnerable).to.be.undefined; |
| 38 | + expect(target).to.not.have.property('__proto__'); |
| 39 | + }); |
| 40 | + |
| 41 | + it('should protect against constructor/prototype pollution', function () { |
| 42 | + const payload = JSON.parse('{"constructor": {"prototype": {"vulnerable": "yes"}}}'); |
| 43 | + const target = {}; |
| 44 | + |
| 45 | + extend(target, payload); |
| 46 | + |
| 47 | + expect({}.vulnerable).to.be.undefined; |
| 48 | + }); |
| 49 | + }); |
| 50 | +}); |
0 commit comments