Skip to content

Commit 2ed8745

Browse files
Security Fix for Prototype Pollution
Fix prototype pollution when path components are not strings
1 parent 03c4efe commit 2ed8745

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ exports.unset = function(path, o) {
143143
if (cur == null || typeof cur !== 'object' || !(parts[i] in cur)) {
144144
return false;
145145
}
146+
if (typeof parts[i] !== 'string' && typeof parts[i] !== 'number') {
147+
parts[i] = String(parts[i]);
148+
}
146149
// Disallow any updates to __proto__ or special properties.
147150
if (ignoreProperties.indexOf(parts[i]) !== -1) {
148151
return false;
@@ -193,6 +196,9 @@ exports.set = function(path, val, o, special, map, _copying) {
193196
if (null == o) return;
194197

195198
for (var i = 0; i < parts.length; ++i) {
199+
if (typeof parts[i] !== 'string' && typeof parts[i] !== 'number') {
200+
parts[i] = String(parts[i]);
201+
}
196202
// Silently ignore any updates to `__proto__`, these are potentially
197203
// dangerous if using mpath with unsanitized data.
198204
if (ignoreProperties.indexOf(parts[i]) !== -1) {
@@ -311,4 +317,4 @@ function _setArray(obj, val, part, lookup, special, map) {
311317

312318
function K(v) {
313319
return v;
314-
}
320+
}

0 commit comments

Comments
 (0)