Skip to content

Commit 2be3354

Browse files
committed
Fix prototype pollution in set()
1 parent 404223b commit 2be3354

File tree

2 files changed

+765
-719
lines changed

2 files changed

+765
-719
lines changed

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@
112112
}
113113
var currentPath = path[0];
114114
var currentValue = getShallowProperty(obj, currentPath);
115+
if (options.includeInheritedProps && (currentPath === '__proto__' ||
116+
(currentPath === 'constructor' && typeof currentValue === 'function'))) {
117+
throw new Error('For security reasons, object\'s magic properties cannot be set')
118+
}
115119
if (path.length === 1) {
116120
if (currentValue === void 0 || !doNotReplace) {
117121
obj[currentPath] = value;

0 commit comments

Comments
 (0)