jonschlinkert / cache-base

Basic object store with methods like get/set/extend/omit
MIT License
56 stars 19 forks source link

Security Fix for Prototype Pollution - huntr.dev #21

Closed huntr-helper closed 3 years ago

huntr-helper commented 3 years ago

https://huntr.dev/users/d3v53c has fixed the Prototype Pollution vulnerability šŸ”Ø. Think you could fix a vulnerability like this?

Get involved at https://huntr.dev/

Q | A Version Affected | ALL Bug Fix | YES Original Pull Request | https://github.com/418sec/cache-base/pull/1 Vulnerability README | https://github.com/418sec/huntr/blob/master/bounties/npm/cache-base/1/README.md

User Comments:

šŸ“Š Metadata *

cache-base is vulnerable to Prototype Pollution.

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

āš™ļø 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 cacheBase = require("cache-base")
const app = new cacheBase();
app.set('__proto__.polluted', 'Yes! Its Polluted');
console.log(app.get('polluted'));

Execute the following commands in terminal:

npm i cache-base # Install affected module
node poc.js #  Run the PoC

Check the Output:

Yes! Its Polluted

šŸ”„ Proof of Fix (PoF) *

Before:

image

After:

image

šŸ‘ User Acceptance Testing (UAT)

image image image

After the fix, functionality is unaffected.

šŸ”— Relates to...

Provide the URL of the PR for the disclosure that this fix relates to.

https://github.com/418sec/huntr/pull/1498

JamieSlome commented 3 years ago

@jonschlinkert - let me know if you have any questions or thoughts, cheers! šŸ°

BeigeBox commented 3 years ago

This looks pretty straight forward to me. @jonschlinkert Could we merge in this PR?

jonschlinkert commented 3 years ago

This is incorrect. This library uses set-value, which ignores unsafe keys: https://github.com/jonschlinkert/set-value/blob/master/index.js#L102.