Skip to content

Commit

Permalink
util.setByPath() - prevent prototype pollution (#1514)
Browse files Browse the repository at this point in the history
  • Loading branch information
kumilingus committed Sep 6, 2021
1 parent 32660d1 commit e5bf89e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/util/util.mjs
Expand Up @@ -140,6 +140,9 @@ export const getByPath = function(obj, path, delimiter) {
const isGetSafe = function(obj, key) {
// Prevent prototype pollution
// https://snyk.io/vuln/SNYK-JS-JSON8MERGEPATCH-1038399
if (typeof key !== 'string' && typeof key !== 'number') {
key = String(key);
}
if (key === 'constructor' && typeof obj[key] === 'function') {
return false;
}
Expand Down
6 changes: 5 additions & 1 deletion test/jointjs/core/util.js
Expand Up @@ -336,7 +336,11 @@ QUnit.module('util', function(hooks) {
assert.deepEqual(joint.util.setByPath({ object: {}}, 'object/1', 'property'), { object: { '1': 'property' }}, 'define property');
});

['__proto__/polluted', 'constructor/prototype/polluted'].forEach(function(path) {
[
'__proto__/polluted',
'constructor/prototype/polluted',
[['__proto__'], 'polluted']
].forEach(function(path) {
QUnit.test('setting "' + path + '" does not pollute prototype' , function(assert) {
var obj = {};
assert.notOk(obj.polluted);
Expand Down

0 comments on commit e5bf89e

Please sign in to comment.