Skip to content

Commit 715555b

Browse files
committed
Merge branch 'pr-40' into dev
2 parents ffe04c3 + 9423fae commit 715555b

File tree

4 files changed

+20
-130
lines changed

4 files changed

+20
-130
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ node_js:
1313
- "iojs-3"
1414
- "iojs-2"
1515
- "iojs-1.0.0"
16+
before_install:
17+
- npm config set strict-ssl false
18+
- npm config set registry="http://registry.npmjs.org/"

lib/deep-extend.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ function deepCloneArray(arr) {
7070
return clone;
7171
}
7272

73+
function safeGetProperty(object, property) {
74+
return property === '__proto__' ? undefined : object[property];
75+
}
76+
7377
/**
7478
* Extening object that entered in first argument.
7579
*
@@ -102,8 +106,8 @@ var deepExtend = module.exports = function (/*obj_1, [obj_2], [obj_N]*/) {
102106
}
103107

104108
Object.keys(obj).forEach(function (key) {
105-
src = target[key]; // source value
106-
val = obj[key]; // new value
109+
src = safeGetProperty(target, key); // source value
110+
val = safeGetProperty(obj, key); // new value
107111

108112
// recursion prevention
109113
if (val === target) {
@@ -141,4 +145,4 @@ var deepExtend = module.exports = function (/*obj_1, [obj_2], [obj_N]*/) {
141145
});
142146

143147
return target;
144-
}
148+
};

test/index.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,14 @@ describe('deep-extend', function () {
254254
});
255255
});
256256

257+
// Vulnerability reported via hacker1: https://hackerone.com/reports/311333
258+
// See https://github.com/unclechu/node-deep-extend/issues/39
259+
// See https://github.com/unclechu/node-deep-extend/pull/40
260+
it('should not modify Object prototype (hacker1 #311333)', function () {
261+
var a = {};
262+
extend({}, JSON.parse('{"__proto__":{"oops":"It works!"}}'))
263+
should.not.exist(a.oops);
264+
should.not.exist(Object.prototype.oops);
265+
});
266+
257267
});

yarn.lock

Lines changed: 0 additions & 127 deletions
This file was deleted.

0 commit comments

Comments
 (0)