Skip to content

Commit 3e1df10

Browse files
committed
Protect against prototype pollution in markup parser
1 parent 0afe3a6 commit 3e1df10

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

src/framework/components/element/markup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ class Parser {
334334
// of assign)
335335
function merge(target, source) {
336336
for (const key in source) {
337-
if (!source.hasOwnProperty(key)) {
337+
if (!source.hasOwnProperty(key) || key === '__proto__' || key === 'constructor' || key === 'prototype') {
338338
continue;
339339
}
340340
const value = source[key];
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { expect } from 'chai';
2+
import { Markup } from '../../../../src/framework/components/element/markup.js';
3+
4+
describe('Markup Prototype Pollution', function () {
5+
it('should ignore sensitive keys like __proto__ during merging', function () {
6+
const symbols = ['[', '_', '_', 'p', 'r', 'o', 't', 'o', '_', '_', ' ', 'p', 'o', 'l', 'l', 'u', 't', 'e', 'd', '=', '"', 't', 'r', 'u', 'e', '"', ']', 'h', 'e', 'l', 'l', 'o'];
7+
8+
// Ensure Object.prototype is clean before test
9+
expect({}.polluted).to.be.undefined;
10+
11+
try {
12+
Markup.evaluate(symbols);
13+
} catch (e) {
14+
// ignore potential errors during evaluation as we only care about pollution
15+
}
16+
17+
expect({}.polluted).to.be.undefined;
18+
});
19+
20+
it('should ignore constructor and prototype keys', function () {
21+
const symbols = ['[', 'c', 'o', 'n', 's', 't', 'r', 'u', 'c', 't', 'o', 'r', ']', 't', 'e', 's', 't'];
22+
23+
const results = Markup.evaluate(symbols);
24+
expect(results.tags).to.not.have.property('constructor');
25+
});
26+
});

0 commit comments

Comments
 (0)