-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Security Fix for Prototype Pollution - huntr.dev #76
Conversation
Security fix for prototype pollution
@chbrown - let me know if you have any thoughts or questions, cheers! 🍰 |
pointer.ts
Outdated
@@ -69,6 +69,8 @@ export class Pointer { | |||
for (let i = 1, l = this.tokens.length; i < l; i++) { | |||
parent = value | |||
key = this.tokens[i] | |||
if (key == '__proto__' || key == 'constructor' || key == 'prototype') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
['__proto__', 'constructor', 'prototype'].includes(key)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved, thanks! 🍰
pointer.ts
Outdated
@@ -69,6 +69,8 @@ export class Pointer { | |||
for (let i = 1, l = this.tokens.length; i < l; i++) { | |||
parent = value | |||
key = this.tokens[i] | |||
if (key == '__proto__' || key == 'constructor' || key == 'prototype') | |||
continue; | |||
// not sure if this the best way to handle non-existant paths... | |||
value = (parent || {})[key] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parent?.[key]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ddimitrioglo - in place of the entire conditional statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value = (parent || {})[key]
=>
value = parent?.[key]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was looking at the wrong line!
Was looking at 72
and 73
! 😝
Will commit and push now...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! 🍰
@chbrown Anything needed to help get this patch merged? |
This PR (well, the lack of merge after so long) has gained some fame. |
@agnihotriwgu Seems like there's already a fix for the vulnerability we're seeing in Veracode -- just not merged in after close to a year (!). @chbrown is there anything else that needs to be done for this PR? |
I was putting this off because I thought there might be a better solution that didn't just skip over these polluting keys but didn't throw an error outright... but I couldn't summon the persistence (interest) to find it. I still don't know why this "vulnerability" is such a big deal but I figure the behavior is broken either way, so if c006ce9 assuages some fears out there, sure, why not. Re: "anything else that needs to be done for this PR?" — it wasn't that hard to cherry-pick out the right commit and assimilate it, but for the record:
Anyhow, fixed in v5.0.0. See https://github.com/chbrown/rfc6902#changelog. |
Thanks for resolving this @chbrown! |
This prevents Prototype Pollution chbrown#76 and fixes a bug with Pointer#set not working with deep paths.
https://huntr.dev/users/arjunshibu 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 | 418sec#1
Vulnerability README | https://github.com/418sec/huntr/blob/master/bounties/npm/rfc6902/1/README.md
User Comments:
📊 Metadata *
rfc6902
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-rfc6902
⚙️ 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) *
🔥 Proof of Fix (PoF) *
Prototype pollution is fixed as seen below.
👍 User Acceptance Testing (UAT)