Prototype Pollution
Description
Prototype Pollution occurs when an attacker can inject properties into the prototype of an object, leading to unintended behavior or security vulnerabilities. This type of attack can affect applications that extend or manipulate JavaScript objects.
Example with Scenario
Scenario: A web application uses user input to create new object properties. An attacker can manipulate the input to modify the prototype of built-in objects, potentially executing arbitrary code or altering application logic.
Payloads and Test Cases
Payloads
Adding a Property:
Modifying an Existing Property:
Nested Property Injection:
Test Cases
Adding a Property:
Payload:
Test Case:
Modifying an Existing Property:
Payload:
Test Case:
Nested Property Injection:
Payload:
Test Case:
Detection and Exploitation with DOM Invader
Detection:
Use Burp Suite's DOM Invader tool to identify vulnerable spots in the application.
Look for points where user input directly influences object properties or prototype chains.
Exploitation:
Use the identified injection points to craft malicious payloads that modify object prototypes.
Test the payloads to see if they lead to security vulnerabilities or application logic changes.
Mitigation
Input Validation:
Validate and sanitize user input to ensure it does not contain malicious characters.
Reject input that attempts to modify object prototypes (e.g., containing
__proto__
,constructor
,prototype
).
Use Object.create(null):
Use
Object.create(null)
to create objects without a prototype.Avoid extending or modifying native object prototypes.
Deep Clone Objects:
Use deep cloning techniques to prevent prototype pollution when merging objects.
Implement secure methods for object manipulation.
Security Libraries:
Use security libraries and frameworks that provide built-in protection against prototype pollution.
Enable and configure security features to prevent injection vulnerabilities.
Last updated