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

Disallow protopath overwrite by avoiding magic attributes #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

d3v53c
Copy link

@d3v53c d3v53c commented Feb 14, 2021

📊 Metadata *

o.set is vulnerable to Prototype Pollution.

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

⚙️ 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 unmodified object, thus fixing the Prototype Pollution Vulnerability.

🐛 Proof of Concept (PoC) *

  1. Create the following PoC file:
// poc.js
var o = require("o.set")
var obj = {};
console.log("Before: " + {}.polluted)
o(obj, "__proto__.polluted", true)
console.log("After: " + {}.polluted)
  1. Execute the following commands in the terminal:
npm i o.set # install vulnerable package
node poc.js # run the PoC
  1. Check the output:
Before: undefined
After: true

🔥 Proof of Fix (PoF) *

Before:
image

After:
image

👍 User Acceptance Testing (UAT)

image

After the fix, functionality is unaffected.

🔗 Relates to...

418sec/huntr#1902

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

👋 Hello, @zewish - @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!

@zewish & @d3v53c - thank you for your efforts in securing the world’s open source code! 🎉

@d3v53c d3v53c changed the title disallow protopath overwrite Disallow protopath overwrite by avoiding magic attributes Feb 14, 2021
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.

2 participants