Skip to content

Commit feaba56

Browse files
authored
fix(security): prevent prototype pollution in memory store (#397)
1 parent 218059e commit feaba56

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/nconf/stores/memory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Memory.prototype.set = function (key, value) {
9292
//
9393
while (path.length > 1) {
9494
key = path.shift();
95-
if (!target[key] || typeof target[key] !== 'object') {
95+
if (!target[key] || typeof target[key] !== 'object' || !Object.hasOwnProperty.call(target, key)) {
9696
target[key] = {};
9797
}
9898

test/stores/memory-store-test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,12 @@ vows.describe('nconf/stores/memory').addBatch({
121121
assert.equal(store.get('foo').bar.bazz, 'buzz');
122122
}
123123
}
124+
},
125+
"When attempting prototype pollution": {
126+
topic: new nconf.Memory(),
127+
"should not be able to pollute the prototype": function (store) {
128+
store.set('__proto__:polluted', 'yes');
129+
assert.equal({}.polluted, undefined);
130+
}
124131
}
125132
}).export(module);

0 commit comments

Comments
 (0)