Skip to content

Commit e5bf89e

Browse files
authored
util.setByPath() - prevent prototype pollution (#1514)
1 parent 32660d1 commit e5bf89e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/util/util.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ export const getByPath = function(obj, path, delimiter) {
140140
const isGetSafe = function(obj, key) {
141141
// Prevent prototype pollution
142142
// https://snyk.io/vuln/SNYK-JS-JSON8MERGEPATCH-1038399
143+
if (typeof key !== 'string' && typeof key !== 'number') {
144+
key = String(key);
145+
}
143146
if (key === 'constructor' && typeof obj[key] === 'function') {
144147
return false;
145148
}

test/jointjs/core/util.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,11 @@ QUnit.module('util', function(hooks) {
336336
assert.deepEqual(joint.util.setByPath({ object: {}}, 'object/1', 'property'), { object: { '1': 'property' }}, 'define property');
337337
});
338338

339-
['__proto__/polluted', 'constructor/prototype/polluted'].forEach(function(path) {
339+
[
340+
'__proto__/polluted',
341+
'constructor/prototype/polluted',
342+
[['__proto__'], 'polluted']
343+
].forEach(function(path) {
340344
QUnit.test('setting "' + path + '" does not pollute prototype' , function(assert) {
341345
var obj = {};
342346
assert.notOk(obj.polluted);

0 commit comments

Comments
 (0)