Skip to content

Commit 8f7f903

Browse files
mriedemaearly
andauthored
Fix prototype pollution vulnerability (#1828)
(cherry picked from commit e1ecdbf) Conflicts: lib/internal/iterator.js test/mapValues.js NOTE(mriedem): The conflicts are due to: - e475117 for iterator.js; resolution was trivial - bd86f42 for mapValues.js; resolution was just copying the test change into the old test file before it was moved This is a 2.x series backport for https://nvd.nist.gov/vuln/detail/CVE-2021-43138. Co-authored-by: Alexander Early <alexander.early@gmail.com>
1 parent f1d8383 commit 8f7f903

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/internal/iterator.js

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ function createObjectIterator(obj) {
2727
var len = okeys.length;
2828
return function next() {
2929
var key = okeys[++i];
30+
if (key === '__proto__') {
31+
return next();
32+
}
3033
return i < len ? {value: obj[key], key: key} : null;
3134
};
3235
}

mocha_test/mapValues.js

+11
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ describe('mapValues', function () {
3939
done();
4040
});
4141
});
42+
43+
it('prototype pollution', (done) => {
44+
var input = JSON.parse('{"a": 1, "b": 2, "__proto__": { "exploit": true }}');
45+
46+
async.mapValues(input, (val, key, next) => {
47+
next(null, val)
48+
}, (err, result) => {
49+
expect(result.exploit).to.equal(undefined)
50+
done(err);
51+
})
52+
})
4253
});
4354

4455
context('mapValues', function () {

0 commit comments

Comments
 (0)