Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security Fix for Prototype Pollution #13

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ exports.unset = function(path, o) {
if (cur == null || typeof cur !== 'object' || !(parts[i] in cur)) {
return false;
}
if (typeof parts[i] !== 'string' && typeof parts[i] !== 'number') {
parts[i] = String(parts[i]);
}
// Disallow any updates to __proto__ or special properties.
if (ignoreProperties.indexOf(parts[i]) !== -1) {
return false;
Expand Down Expand Up @@ -193,6 +196,9 @@ exports.set = function(path, val, o, special, map, _copying) {
if (null == o) return;

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

function K(v) {
return v;
}
}