Skip to content

Commit e431eff

Browse files
committed
fix prototype pollution vulnerability
cheers Daniel Elkabes of WhiteSource Software
1 parent a883c87 commit e431eff

File tree

3 files changed

+2765
-3
lines changed

3 files changed

+2765
-3
lines changed

index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,31 @@ function recursivelySetIn (object, path, value, index) {
1616

1717
object = object || {}
1818

19+
// https://stackoverflow.com/a/60850027
20+
assert.ok(
21+
path[index] !== '__proto__',
22+
'setIn: "__proto__" is disallowed in path due to possible prototype pollution attack.'
23+
)
24+
if (index < path.length - 1) {
25+
assert.ok(
26+
path[index] !== 'constructor' && path[index + 1] !== 'prototype',
27+
'setIn: ["constructor", "prototype"] is disallowed in path due to possible prototype pollution attack.'
28+
)
29+
}
30+
1931
var key = path[index]
2032

2133
if (key === '-') {
2234
assert.ok(Array.isArray(object), 'setIn: "-" in path must correspond to array.')
2335
key = object.length
2436
}
2537

38+
if (
39+
key === '__proto__' ||
40+
(key === 'constructor' && path[index + 1] === 'prototype')) {
41+
42+
}
43+
2644
var next = recursivelySetIn(object[key], path, value, ++index)
2745

2846
return set(object, key, next)

0 commit comments

Comments
 (0)