Skip to content

Commit 086b19d

Browse files
fix: do not allow setting __proto__ in Message constructor (#2126)
When a properties object passed to Message constructor contains __proto__, such as in const properties = JSON.parse('{"__proto__": {"polluted": "yes"}}'); const message = new protobuf.Message(properties); the resulting message object will have message.polluted defined which is not intended. Filter out __proto__ when iterating over the keys of the properties.
1 parent 827ff8e commit 086b19d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/message.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ var util = require("./util/minimal");
1313
function Message(properties) {
1414
// not used internally
1515
if (properties)
16-
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
17-
this[keys[i]] = properties[keys[i]];
16+
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) {
17+
var key = keys[i];
18+
if (key === "__proto__")
19+
continue;
20+
this[key] = properties[key];
21+
}
1822
}
1923

2024
/**
@@ -136,4 +140,4 @@ Message.prototype.toJSON = function toJSON() {
136140
return this.$type.toObject(this, util.toJSONOptions);
137141
};
138142

139-
/*eslint-enable valid-jsdoc*/
143+
/*eslint-enable valid-jsdoc*/

0 commit comments

Comments
 (0)