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

Conversation

@d3v53c
Copy link

@d3v53c d3v53c commented Nov 26, 2020

📊 Metadata *

convict 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-convict/

⚙️ 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 convict = require("convict");
var obj = {};
var config = convict(obj);
console.log("Before : " + {}.polluted);
config.set("__proto__.polluted","Yes! Its Polluted");
console.log("After : " + {}.polluted);

Execute the following commands in another terminal:

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

Check the Output:

Before : undefined
After : Yes! Its Polluted

🔥 Proof of Fix (PoF) *

Before:

image

After:

image

👍 User Acceptance Testing (UAT)

After fix, functionality is unaffected.

@d3v53c d3v53c changed the title prototype pollution fix Prototype pollution fix: Avoid setting magic attributes Nov 26, 2020
@JamieSlome JamieSlome requested a review from mzfr December 16, 2020 14:21
Copy link

@mzfr mzfr left a comment

Choose a reason for hiding this comment

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

LGTM!

EDIT: Noticed a bit later that there are two more PR for the same fix.

See this

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 😄 🍰

Screenshot from 2020-12-28 18-58-30

Cheers,
Mik

Copy link

@mzfr mzfr left a comment

Choose a reason for hiding this comment

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

LGTM!

@JamieSlome JamieSlome closed this Jan 13, 2021
@huntr-helper
Copy link

Sorry d3v53c, we enjoyed reviewing your fix but it has not been selected this time. If this bounty has not been closed, please feel free to try again with a new pull request!

We appreciate your effort and look forward to reviewing more of your fixes in the future! 🔨😎

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

Development

Successfully merging this pull request may close these issues.

5 participants