Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Prototype pollution fix - checking magic attributes - grpc-js #3

Merged
merged 2 commits into from Dec 16, 2020

Conversation

d3v53c
Copy link

@d3v53c d3v53c commented Dec 8, 2020

馃搳 Metadata *

grpc is vulnerable to Prototype Pollution. This package allowing for modification of prototype behavior, which may result in Information Disclosure/DoS/RCE.

Bounty URL: https://www.huntr.dev/bounties/1-npm-grpc

鈿欙笍 Description *

Prototype Pollution refers to the ability to inject properties into existing JavaScript language construct prototypes, such as objects.
JavaScript allows all Object attributes to be altered, including their magical attributes such as proto, constructor and prototype.
An attacker manipulates these attributes to overwrite, or pollute, a JavaScript application object prototype of the base object by injecting other values.
Properties on the Object.prototype are then inherited by all the JavaScript objects through the prototype chain.

馃捇 Technical Description *

Fixed by avoiding setting magical attributes. The bug is fixed by validating the input strArray to check for prototypes. It is implemented by a simple validation to check for prototype keywords (proto, constructor and prototype), where if it exists, the function returns the object without modifying it, thus fixing the Prototype Pollution Vulnerability.

馃悰 Proof of Concept (PoC) *

Create the following PoC file:

// poc.js
var grpc =require('grpc')
grpc.loadPackageDefinition({'constructor.prototype.polluted': { service: "Yes! Its Polluted" }});
console.log({}.polluted)

Execute the following commands in another terminal:

npm i grpc # Install affected module
node poc.js # Run the PoC

Check the Output:

[Function: ServiceClient] { service: 'Yes! Its Polluted' }`

馃敟 Proof of Fix (PoF) *

Before:
image

After:
image

馃憤 User Acceptance Testing (UAT)

After fix functionality is unaffected.

grpc-proto-test-1

grpc-proto-test-2
grpc-proto-test-3
grpc-proto-test-4
grpc-proto-test-5
grpc-proto-test-6
grpc-proto-test-7

Copy link

@bbeale bbeale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grpc-fix-2

Copy link

@Mik317 Mik317 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 馃槃 馃嵃

Cheers,
Mik

@huntr-helper
Copy link
Member

Congratulations d3v53c - your fix has been selected! 馃帀

Thanks for being part of the community & helping secure the world's open source code.
If you have any questions, please respond in the comments section, or hit us up on Discord. Your bounty is on its way - keep hunting!

Come join us on Discord

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
5 participants