Skip to content

Commit f272681

Browse files
committedFeb 17, 2020
fix: prevent changes in prototype chain
1 parent f495954 commit f272681

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed
 

‎lib/undefsafe.js

+4
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ function undefsafe(obj, path, value, __res) {
9999
return res;
100100
}
101101

102+
if (Object.getOwnPropertyNames(obj).indexOf(key) == -1) {
103+
return undefined;
104+
}
105+
102106
obj = obj[key];
103107
if (obj === undefined || obj === null) {
104108
break;

‎test/misc.test.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var test = require('tap').test;
2+
var undefsafe = require('../lib/undefsafe');
3+
4+
test('cannot modify prototype chain', function(t) {
5+
const pre = {}.__proto__.toString;
6+
var payload = '__proto__.toString';
7+
undefsafe({ a: 'b' }, payload, 'JHU');
8+
t.notEqual({}.toString, 'JHU');
9+
({}.__proto__.toString = pre); // restore
10+
t.end();
11+
});

0 commit comments

Comments
 (0)
Please sign in to comment.