Client-Side Prototype Pollution

Client-side JavaScript copies attacker-controllable keys from the URL or other input into objects, polluting the page's prototype and often enabling DOM-based XSS through gadgets.

SeverityMedium
CVSS 3.14.7 CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:L/I:L/A:N Open in the calculator
CVSS 4.02.1 CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:A/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N Open in the calculator
CWECWE-1321: Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution')
MITRE ATT&CKT1189 Drive-by Compromise
CategoryInput Validation

Description

Client-side JavaScript in the application parses data that an attacker can control, most often the query string or fragment of the URL, into nested objects, or merges such data into existing objects, with code that does not exclude the keys __proto__, constructor and prototype. A crafted link containing, for example, ?__proto__[test]=value then adds a property to Object.prototype in the victim's browser, so that every object on the page appears to have it. The vulnerable code is frequently in a third-party library, such as an older URL parameter parser or deep-merge function.

Pollution alone changes little, and without a gadget the effect is usually limited to changing the page's behaviour. The impact comes from gadgets: code in the page or its libraries that reads a property which is normally undefined and uses it in a dangerous way, for example as the address of a script or as HTML written into the page, which turns the pollution into DOM-based cross-site scripting. Where such a gadget exists, an attacker who persuades a victim to follow a crafted link can run script in the victim's session, reading data shown to them and acting on their behalf. The outcome therefore depends on the libraries the page loads.

The weakness typically shows itself on a test when a prototype key in the URL makes the property appear on new objects in the browser console. Burp Suite's DOM Invader finds both pollution sources and known gadgets, and Burp Suite's scanner reports client-side prototype pollution.

Remediation

Remove the pollution source and reduce what gadgets can do:

  • Update or replace third-party libraries with known prototype pollution flaws, and keep client-side dependencies under regular review.
  • Do not parse URL parameters or other untrusted input into nested objects with generic code. Read individual parameters with URLSearchParams, and copy only expected properties.
  • Reject the keys __proto__, constructor and prototype in any merge or assignment code, and use Map or Object.create(null) for dictionaries built from input.
  • Consider freezing Object.prototype early in page load, after testing that the page still works.
  • Limit the effect of gadgets with a Content Security Policy that restricts script sources and, in supporting browsers, Trusted Types.

Confirm the fix by repeating the original crafted URLs and checking that no property is added to Object.prototype and no gadget fires.

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 trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More Web Applications Findings

Every Web Applications finding