Server-Side Prototype Pollution
Server-side JavaScript merges user-supplied keys such as __proto__ into objects, so an attacker can add properties to every object in the application process.
| Severity | High |
| CVSS 3.1 | 8.1 CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H Open in the calculator |
| CVSS 4.0 | 9.2 CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N Open in the calculator |
| CWE | CWE-1321: Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution') |
| MITRE ATT&CK | T1190 Exploit Public-Facing Application |
| Category | Input Validation |
Description
The application, typically built on Node.js, copies values from user-supplied JSON or query parameters into objects with a recursive merge, clone or path-assignment function that does not exclude the special keys __proto__, constructor and prototype. A request containing such a key then adds or changes properties on Object.prototype, which almost every object in the process inherits, so the injected value appears wherever the code reads a property that an object does not set itself. The vulnerable function may be in the application or in a dependency, as several popular merge and query-parsing libraries have had this flaw.
The impact depends on gadgets: code that reads an inherited property and uses it in a security decision, a configuration option or a dangerous function, such as the options passed to child_process functions. Through them an attacker can escalate privileges by injecting properties such as role flags, change application behaviour for all users, cause a denial of service that lasts until the process restarts, or run arbitrary code on the server, for example through options that control how child processes are started; code execution, where achievable, compromises the application host. No authentication is needed where an affected endpoint is public.
The weakness typically shows itself on a test through non-destructive changes, such as polluting a property that alters the formatting or status code of JSON responses, followed by a search for gadgets. Burp Suite includes checks for server-side prototype pollution. Testing needs care, because a polluted prototype persists for the life of the process and affects every user until the application restarts.
Remediation
Stop untrusted keys from reaching object prototypes:
- Do not merge, clone or assign user-supplied objects into application objects with generic recursive functions. Copy only expected properties, or validate request bodies against a strict schema that rejects unknown properties.
- Where recursive merging is needed, use library versions that are patched against prototype pollution, and reject the keys
__proto__,constructorandprototypeat every level. - Use
Mapobjects, or objects created withObject.create(null), for dictionaries built from user input, so that they have no prototype to pollute. - Consider freezing
Object.prototypeat start-up withObject.freeze(), after testing that dependencies still work, and running Node.js with--disable-proto=deleteas defence in depth. - Keep dependencies up to date, and use software composition analysis to find vulnerable merge and parsing libraries.
Confirm the fix by repeating the original requests with prototype keys and checking that no property is added to unrelated objects, then restart the application to clear any pollution left by testing.
References
Add This Finding to Your Library
In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.
Free trialYour trial starts when your portal goes live, not when you sign up, so the time you spend setting up does not count. · No card required
Only need the reporting? Our reporting tool is free and open source, with the same library.