Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security Fix for Prototype Pollution - huntr.dev #262

Merged

Conversation

huntr-helper
Copy link

https://huntr.dev/users/alromh87 has fixed the Prototype Pollution vulnerability 馃敤. alromh87 has been awarded $25 for fixing the vulnerability through the huntr bug bounty program 馃挼. 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#2
Vulnerability README | https://github.com/418sec/huntr/blob/master/bounties/npm/fast-json-patch/1/README.md

User Comments:

馃搳 Metadata *

fast-json-patch 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-fast-json-patch

鈿欙笍 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 missing magical attributes.

馃悰 Proof of Concept (PoC) *

  1. Create the following PoC file:
// poc.js
let fastjsonpatch = require("fast-json-patch");
function A() {}
let a = new A();
let b = new A();
console.log("Before : " + a.polluted);
console.log("Before : " + b.polluted);
const patch = [{op: "replace", path: "/constructor/prototype/polluted", value: "Yes! Its Polluted"}];
fastjsonpatch.applyPatch(a, patch);
console.log("After : " + a.polluted);
console.log("After : " + b.polluted);
  1. Execute the following commands in another terminal:
npm i fast-json-patch # Install affected module
node poc.js #  Run the PoC
  1. Check the Output:
Before : undefined
Before : undefined
After : Yes! Its Polluted
After : Yes! Its Polluted

Captura de pantalla de 2020-10-22 13-56-22

馃敟 Proof of Fix (PoF) *

After fix and exception will be thrown

Captura de pantalla de 2020-10-22 13-55-23

馃憤 User Acceptance Testing (UAT)

After fix functionality is unafected

@JamieSlome
Copy link
Contributor

JamieSlome commented Oct 22, 2020

@Starcounter-Jack @warpech - let me know if you have any thoughts or questions!

Cheers! 馃嵃

@nicdumz
Copy link

nicdumz commented May 30, 2021

@alromh87 @Starcounter-Jack @JamieSlome it looks like this PR would need a bit of love in order to be merged :-)

@alromh87
Copy link
Contributor

alromh87 commented Jun 2, 2021

@nicdumz would the needed love would be merge latest changes or should it include something else?

鈥 into enhancePR

Conflicts:
	commonjs/core.js
	module/core.mjs
	src/core.ts
@alromh87
Copy link
Contributor

alromh87 commented Jun 2, 2021

updated to latest master @ alromh87@f76022e
@JamieSlome should I PR to 418sec repo?

@JamieSlome
Copy link
Contributor

@alromh87 - merged!

@nicdumz
Copy link

nicdumz commented Jun 2, 2021

Great, thanks! @Starcounter-Jack this PR is now conflict-free.

For the record, I became interested in the topic this weekend as there was a CTF task combining this fast-json-patch unpatched problem and an EJS vuln to get RCE. One good writeup, here, even mentions this unmerged PR ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants