Skip to content

Commit

Permalink
Merge pull request #1701 from murgatroid99/grpc_prototype_pollution_fix
Browse files Browse the repository at this point in the history
grpc: Fix prototype pollution possibility in loadPackageDefinition
  • Loading branch information
murgatroid99 committed Mar 1, 2021
2 parents ea5b04e + 9153fd2 commit 545a935
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/grpc-native-core/index.js
Expand Up @@ -161,7 +161,7 @@ exports.loadPackageDefinition = function loadPackageDefintion(packageDef) {
for (const serviceFqn in packageDef) {
const service = packageDef[serviceFqn];
const nameComponents = serviceFqn.split('.');
if (nameComponents.some(comp => comp === '__proto__')) {
if (nameComponents.some(comp => common.isPrototypePolluted(comp))) {
continue;
}
const serviceName = nameComponents[nameComponents.length-1];
Expand Down
2 changes: 1 addition & 1 deletion packages/grpc-native-core/package.json
@@ -1,6 +1,6 @@
{
"name": "grpc",
"version": "1.24.5",
"version": "1.24.6",
"author": "Google Inc.",
"description": "gRPC Library for Node",
"homepage": "https://grpc.io/",
Expand Down
4 changes: 2 additions & 2 deletions packages/grpc-native-core/src/client.js
Expand Up @@ -992,7 +992,7 @@ exports.makeClientConstructor = function(methods, serviceName,

Object.keys(methods).forEach(name => {
const attrs = methods[name];
if (name === '__proto__') {
if (common.isPrototypePolluted(name)) {
return;
}
if (name.indexOf('$') === 0) {
Expand All @@ -1014,7 +1014,7 @@ exports.makeClientConstructor = function(methods, serviceName,
ServiceClient.prototype.$method_names[attrs.path] = name;
// Associate all provided attributes with the method
Object.assign(ServiceClient.prototype[name], attrs);
if (attrs.originalName && attrs.originalName !== '__proto__') {
if (attrs.originalName && !common.isPrototypePolluted(attrs.originalName)) {
ServiceClient.prototype[attrs.originalName] =
ServiceClient.prototype[name];
}
Expand Down
10 changes: 10 additions & 0 deletions packages/grpc-native-core/src/common.js
Expand Up @@ -148,6 +148,16 @@ exports.zipObject = function(props, values) {
}, {});
}

/**
* Returns true, if given key is included in the blacklisted
* keys.
* @param key {String} key for check, string.
* @return {Boolean}
*/
exports.isPrototypePolluted = function(key) {
return ['__proto__', 'prototype', 'constructor'].indexOf(key) >= 0;
}

// JSDoc definitions that are used in multiple other modules

/**
Expand Down

0 comments on commit 545a935

Please sign in to comment.