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/native-core #6

Closed
wants to merge 2 commits into from

Conversation

d3v53c
Copy link

@d3v53c d3v53c commented Jan 26, 2021

馃搳 Metadata *

grpc native core package 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/2-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)

image

After the fix, functionality is unaffected.

A breaking change is introduced, the fix wont allow the client to alter and modify the prototype properties of an object, using the methods loadPackageDefinition, makeClientConstructor .

馃敆 Relates to...

418sec/huntr#1792

huntr-helper pushed a commit to 418sec/huntr that referenced this pull request Jan 26, 2021
@huntr-helper
Copy link
Member

馃憢 Hello, @murgatroid99 - @d3v53c has opened a PR to us with a fix for a potential vulnerability in your repository. To view the vulnerability, please refer to the bounty URL in the first comment, above.

Ultimately, you get to decide if the fix is 馃憤 or 馃憥. If you are happy with the fix, please write a new comment (@huntr-helper - LGTM) and we will open a PR to your repository with the fix. All remaining PRs for this vulnerability will be automatically closed.

If you have any questions or need support, come and join us on our community Discord!

@murgatroid99 & @d3v53c - thank you for your efforts in securing the world鈥檚 open source code! 馃帀

@d3v53c
Copy link
Author

d3v53c commented Feb 14, 2021

Hi @murgatroid99,

Mentioning relevant PR..

@d3v53c
Copy link
Author

d3v53c commented Mar 2, 2021

Closing this since fix merged upstream..

For reference, see PR

@d3v53c d3v53c closed this Mar 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants