[json8-merge-patch] Prototype Pollution
The apply function in json8-merge-patch does not restrict access to object prototypes, allowing an attacker to modify prototype behaviour. This could lead to sensitive information disclosure, denial of service, or remote code execution depending on how the library is used.
- Disclosed after 36 days
I would like to report a Prototype Pollution vulnerability in json8-merge-patch
The apply function fails to restrict access to prototypes of objects, allowing for modification of prototype behavior.
Module
module name: json8-merge-patch
version: v1.0.1
npm page: https://www.npmjs.com/package/json8-merge-patch
Module Description
JSON Merge Patch RFC 7396 toolkit for JavaScript.
Module Stats
Weekly downloads: 517
Vulnerability
Vulnerability Description
The apply function fails to restrict access to prototypes of objects, allowing for modification of prototype behavior, which may allow obtaining sensitive information/DoS/RCE.
Steps To Reproduce:
-
Install
json8-merge-patchmodulenpm i json8-merge-patch -
create a file
poc.jswith content :
let json8mergepatch = require("json8-merge-patch");
var obj = {}
console.log("Before : " + obj.isAdmin);
json8mergepatch.apply(obj, JSON.parse('{ "__proto__": { "isAdmin": true }}'));
console.log("After : " + obj.isAdmin);
- Execute using:
node poc.js
##Output: Before: undefined After: true
Supporting Material/References:
- OPERATING SYSTEM VERSION: Windows 10
- NODEJS VERSION: v12.18.3
- NPM VERSION: 6.14.6
Wrap up
- I contacted the maintainer to let them know: [Y]
- I opened an issue in the related repository: [Y]
Ref: https://github.com/sonnyp/JSON8/issues/113
Impact
Can result in sensitive information disclosure/DoS/RCE. (depends on implementation)
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The apply function does not block the special __proto__ key when merging objects, so it writes to the prototype instead of the object itself.
Impact
Depending on how the library is used, this could lead to sensitive information disclosure, denial of service, or remote code execution.
What the attacker needed
Application uses json8-merge-patch with untrusted JSON
How it was found
- Install the json8-merge-patch module.
- Create a JavaScript file that requires the module and defines an empty object.
- Call the apply function with the empty object and a parsed JSON object containing a __proto__ key with a property set to true.
- Run the file with Node.js and observe that the object now has the property from the prototype.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Prototype pollution is a bug where an attacker can change properties on a shared object that other objects inherit from. Here, a function that merges JSON data let a malicious input set a property on that shared object. This can break the application or, in some cases, may allow an attacker to run their own code.
What is Prototype pollution?
Input changes JavaScript's shared object prototype, altering behaviour across the application, sometimes to XSS or code execution.