Skip to content

Commit d3e6633

Browse files
committed
fix prototype pollution bypass in extend() util
Replace array indexOf check with direct string comparison to prevent bypass via Array.prototype.indexOf override.
1 parent 70c48c1 commit d3e6633

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/shared/utils.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,12 @@ function isNode(node) {
102102
}
103103
function extend(...args) {
104104
const to = Object(args[0]);
105-
const noExtend = ['__proto__', 'constructor', 'prototype'];
106105
for (let i = 1; i < args.length; i += 1) {
107106
const nextSource = args[i];
108107
if (nextSource !== undefined && nextSource !== null && !isNode(nextSource)) {
109-
const keysArray = Object.keys(Object(nextSource)).filter((key) => noExtend.indexOf(key) < 0);
108+
const keysArray = Object.keys(Object(nextSource)).filter(
109+
(key) => key !== '__proto__' && key !== 'constructor' && key !== 'prototype',
110+
);
110111
for (let nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex += 1) {
111112
const nextKey = keysArray[nextIndex];
112113
const desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);

0 commit comments

Comments
 (0)