A simple diagram of the JavaScript Prototype Pollution risk path
Risk path: an input or context crosses a security boundary.
A simple three-step test path for JavaScript Prototype Pollution
Testing path: establish a baseline, make one controlled change, and verify the effect.

01Issue

Overview

JavaScript objects can inherit properties from a prototype. Prototype pollution occurs when untrusted input changes a shared prototype, often through a recursive merge or path-based assignment using keys such as __proto__ or constructor.prototype. Other objects may then appear to have properties that were never set on them directly. The changed property is only dangerous if application code later reads it in a meaningful way.

Common causes

  • A recursive merge copies special property names into ordinary objects.
  • A nested property setter follows attacker-chosen paths without blocking prototype keys.
  • Untrusted configuration or profile data is merged into shared objects.
  • A vulnerable dependency performs unsafe merge, clone, or path assignment.

References: OWASP WSTG: Prototype Pollution ↗CWE-1321: Prototype Pollution ↗MDN: Object prototype ↗

02Examples

EXAMPLE

Illustrative unit test in an isolated runtime: parse {"__proto__":{"testMarker":"set"}} through the suspected merge function, then check ({}).testMarker. If it returns set, the shared prototype was changed in that process. This confirms pollution in the tested path, but a separate code path must be shown before claiming a broader impact.

03Impact

Attacker-controlled structured input must reach an unsafe assignment or merge. To establish a security impact, show that the shared prototype changes and identify reachable application code that uses the polluted property in a sensitive way. The special key appearing in a request is only a test input.

Effects range from changed defaults or application behavior to security bypasses or script execution when a suitable consumer exists. Pollution alone does not prove a gadget or harmful action. Report the actual changed property and its demonstrated use.

04Testing

Test cases

1. Check whether input alters object properties beyond its own record

Submit a controlled marker through a merge or parsing path and inspect whether another test object inherits the unexpected property. Verify whether the application makes a relevant decision from it.

Example: A key being accepted is only a clue. An inherited marker on an unrelated object is stronger evidence.

POST /api/preferences HTTP/1.1
Host: app.example.test
Content-Type: application/json
 
{"__proto__":{"pollutionMarker":"demo"}}

2. Compare nested keys and merge paths

Test supported nested request fields and the application’s parser or merge functions. Check alternate property paths only where the runtime and library make them relevant.

Example: Different libraries handle special keys differently. Observe the actual object behavior in the test environment.

POST /api/preferences HTTP/1.1
Host: app.example.test
Content-Type: application/json
 
{"constructor":{"prototype":{"pollutionMarker":"demo"}}}

3. Review security-sensitive uses and cleanup

Trace polluted properties to the application behavior that consumes them and reset the test process after checks. Separate a confirmed polluted property from any claimed access or code execution.

Example: A changed object property does not automatically prove remote code execution. Confirm the specific downstream effect.

Testing references: OWASP WSTG: Prototype Pollution ↗CWE-1321: Prototype Pollution ↗MDN: Object prototype ↗

05Mitigation

Reject __proto__, constructor, and prototype keys before assigning user-controlled objects. Validate data with a strict schema, use Map or null-prototype objects for dictionaries, and prefer maintained merge utilities with safe behavior. Keep dependencies updated. Review and remove code that reads security-sensitive settings from inherited properties.

Retest

Repeat the unique-property probe in an isolated test process and verify fresh objects remain unchanged. Confirm the application’s relevant feature still accepts expected data and no sensitive consumer can use attacker-controlled inherited properties.