Skip to content

Commit e66379f

Browse files
authoredJun 23, 2023
fix: do not let setProperty change the prototype (#1899)
* fix: do not let setProperty change the prototype * test: add unit test
1 parent 56b1e64 commit e66379f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed
 

‎src/util.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ util.decorateEnum = function decorateEnum(object) {
176176
util.setProperty = function setProperty(dst, path, value) {
177177
function setProp(dst, path, value) {
178178
var part = path.shift();
179-
if (part === "__proto__") {
179+
if (part === "__proto__" || part === "prototype") {
180180
return dst;
181181
}
182182
if (path.length > 0) {

‎tests/api_util.js

+9
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ tape.test("util", function(test) {
9595

9696
util.setProperty(o, 'prop.subprop', { subsub2: 7});
9797
test.same(o, {prop1: [5, 6], prop: {subprop: [{subsub: [5,6]}, {subsub2: 7}]}}, "should convert nested properties to array");
98+
99+
util.setProperty({}, "__proto__.test", "value");
100+
test.is({}.test, undefined);
101+
102+
util.setProperty({}, "prototype.test", "value");
103+
test.is({}.test, undefined);
104+
105+
util.setProperty({}, "constructor.prototype.test", "value");
106+
test.is({}.test, undefined);
98107

99108
test.end();
100109
});

0 commit comments

Comments
 (0)
Please sign in to comment.