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

Fixed Prototype Pollution #2

Merged
merged 2 commits into from
Apr 24, 2020
Merged

Fixed Prototype Pollution #2

merged 2 commits into from
Apr 24, 2020

Conversation

mufeedvh
Copy link

⚙️ Fix:

The fix is implemented by defining the input Object with Object.create(null). An Object created through this API won’t have any prototype attributes which prevent Prototype Pollution Attacks.

How:

The main assocInM() function has 3 parameters obj, keys, and value. The obj parameter is the object being mutated in this function.

The payload is however passed as an array to the keys parameter and the value to set inside the object to the value parameter as per the PoC:

var a = require("./index.js"); 
a.assocInM({},["__proto__","toString"],"JHU"); 
console.log({}.toString);

These values (with the payload) is mutated in this function which causes prototype pollution, I used the Object.create() to define the object to not contain any prototypes before the mutations start.

This fix is implemented with the help of this paper on Prototype Pollution:

🗒️ Prototype pollution attack in NodeJS application

From Mitigation Methods -> Object.create(null) (from the paper):

It’s possible to create object in JavaScript that don’t have any prototype. It requires the
usage of the “Object.create” function. Object created through this API won’t have the
proto” and “constructor” attributes. Creating object in this fashion can help mitigate
prototype pollution attack.

  1. var obj = Object.create(null);
  2. obj.proto // undefined
  3. obj.constructor // undefined

🗒️ Proof of Concept:

Place the below PoC in the root folder of the project as poc.js

var a = require("./index.js"); 
a.assocInM({},["__proto__","toString"],"JHU"); 
console.log({}.toString);

🔥 Steps to Reproduce:

$ cd fun-map/
$ node poc.js

❤️ After Fix Screenshot:

fun-map-prototype-pollution-fix


✌️ Fixed!


@JamieSlome JamieSlome requested a review from adam-nygate April 24, 2020 09:50
Copy link

@toufik-airane toufik-airane left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Copy link
Member

@adam-nygate adam-nygate left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@huntr-helper
Copy link

Congratulations @mufeedvh - 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. Your bounty is on its way - keep hunting!

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.

4 participants