@theecryptochad/merge-guard Prototype Pollution Vulnerability
`@theecryptochad/merge-guard` versions prior to 1.0.1 are vulnerable to Prototype Pollution via the `deepMerge()` function, allowing an attacker who controls the source object to inject `__proto__` keys that mutate `Object.prototype`, affecting all objects in the Node.js runtime.
The @theecryptochad/merge-guard npm package, specifically versions prior to 1.0.1, contains a prototype pollution vulnerability in its deepMerge() function. This vulnerability arises from the lack of sanitization of reserved property keys like __proto__ during the recursive merging of objects. If an attacker can control the contents of the source object passed to deepMerge(), they can inject __proto__ properties that modify the base Object.prototype. This pollution affects all objects within the Node.js runtime, potentially leading to privilege escalation, application logic bypass, or other unexpected behavior. Successful exploitation requires the application to use deepMerge() with user-controlled input.
Attack Chain
- The application receives untrusted data from an external source (e.g., HTTP request, WebSocket message, config file).
- The untrusted data is parsed as a JSON object.
- The attacker crafts the JSON object to include a
__proto__property with a malicious payload as its value. For example:{"__proto__": {"isAdmin": true}}. - The
deepMerge()function is called with a target object and the attacker-controlled JSON object as the source. - Due to the missing sanitization, the
__proto__property in the source object overwrites theObject.prototypewith the malicious payload. - Subsequently, all objects in the Node.js runtime inherit the injected properties (e.g.,
isAdmin: true). - The attacker leverages the polluted
Object.prototypeto bypass application logic or escalate privileges. - The application’s behavior is altered, potentially leading to data breaches, unauthorized access, or other security impacts.
Impact
Applications using vulnerable versions of @theecryptochad/merge-guard and passing unsanitized user-supplied data to the deepMerge() function are at risk. An attacker can inject arbitrary properties onto Object.prototype, leading to privilege escalation and application logic bypass. The number of affected applications is currently unknown, but the risk is significant for applications that process untrusted input. A successful attack allows the attacker to modify the behavior of the entire Node.js application.
Recommendation
- Upgrade to
@theecryptochad/merge-guard >= 1.0.1to remediate the vulnerability. This version adds a blocklist to prevent modification of__proto__,constructor, andprototypeproperties (see Remediation section in Content). - Deploy the Sigma rule “Detect Prototype Pollution via deepMerge” to detect attempts to exploit this vulnerability via HTTP requests containing
__proto__keys (see Rules). - Sanitize all user-supplied data before passing it to
deepMerge()to prevent the injection of malicious properties.
Detection coverage 2
Detect Prototype Pollution via deepMerge
highDetects HTTP requests attempting to exploit Prototype Pollution in deepMerge functions by searching for __proto__ in request parameters.
Detect deepMerge with user-controlled input
mediumDetects usage of deepMerge function calls with user-controlled input as a parameter.
Detection queries are available on the platform. Get full rules →