Skip to content

Commit 2789069

Browse files
committed
Updated prototype pollution fix
1 parent 9e569b7 commit 2789069

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,18 @@ module.exports = function (bodyParser) {
4343
return next(err);
4444
}
4545

46-
// Set the prototype of parsed xml object to null, so that prototype pollution is prevented.
47-
xml.__proto__ = undefined;
48-
req.body = xml || req.body;
46+
// Prevent setting __proto__ and constructor.prototype
47+
const safe = {};
48+
for (const key in xml) {
49+
if (
50+
key !== '__proto__' &&
51+
key !== 'constructor' &&
52+
key !== 'prototype'
53+
) {
54+
safe[key] = xml[key];
55+
}
56+
}
57+
req.body = safe || req.body;
4958
next();
5059
});
5160
});

0 commit comments

Comments
 (0)