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

Fixed Prototype Pollution Bug by ignoring dangerous keys #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

arjunshibu
Copy link

📊 Metadata *

join-assign is vulnerable to Prototype Pollution.

Bounty URL: https://www.huntr.dev/bounties/1-npm-join-assign

⚙️ 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 *

Fix implemented by not allowing to modify object prototype.

🐛 Proof of Concept (PoC) *

  1. Create the following PoC file:
// poc.js
const { assign } = require('./src')

console.log('Before: ' + {}.polluted)
assign({}, JSON.parse('{"__proto__": {"polluted": true}}'))
console.log('After: ' + {}.polluted)
  1. Execute the following commands in terminal:
npm i join-assign # Install affected module
node poc.js #  Run the PoC
  1. Check the Output:
Before : undefined
After : true

🔥 Proof of Fix (PoF) *

image

+1 User Acceptance Testing (UAT)

  • I've executed unit tests.
  • After fix the functionality is unaffected.

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

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

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

@dgchrt
Copy link

dgchrt commented Feb 13, 2021

Hi! Thank you very much for this. While I truly appreciate the collaboration, I must say I don't agree with the solution, specially because I don't see this as a problem this package should try to solve. If the prototype has been polluted already by the time join-assign performs an assign or clone operation, it means the problem should have been prevented at an earlier point, most likely avoiding random code from other dependencies to be executed.

That being said, this change would also break some important functionality currently available, like the creation of multi-inheritance instances, e.g.

		function A() {
			this.a = 1;
		}

		function B() {}

		B.prototype.b = function () {
			return this.a;
		};

		const a = new A();
		const b = new B();
		join.assign(a, b);
		a.b(); // should be able to call this method and return 1

I have extended the unit tests to cover this case specifically. To run the tests, you can rebase your branch from the main branch and run npm test. Thanks again.

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.

3 participants