CWE-1321: Prototype Pollution
Improperly Controlled Modification of Object Prototype Attributes
The product receives input from an upstream component that specifies attributes that are to be initialized or updated in an object, but it does not properly control modifications of attributes of the object prototype.
How it's found
Prototype Pollution is a specific, narrowly defined instance of a broader pattern. Testers confirm it with targeted code review and a proof-of-concept input that exercises the exact code path this weakness describes.
Vulnerable vs. safe
objectToModify[attr] = {};}if (typeof objectToModify[attr] !== 'object') {objectToModify = objectToModify[attr];}const pathArray = path.split(".");const attributeToSet = pathArray.pop();let objectToModify = object;for (const attr of pathArray) {objectToModify[attributeToSet] = value;return object;}function setValueByPath (object, path, value) {// Ignore attributes which resolve to object prototype
continue;}
objectToModify[attr] = {};}if (attr === "__proto__" || attr === "constructor" || attr === "prototype") {if (typeof objectToModify[attr] !== "object") {objectToModify = objectToModify[attr];}const pathArray = path.split(".");const attributeToSet = pathArray.pop();let objectToModify = object;for (const attr of pathArray) {objectToModify[attributeToSet] = value;return object;}function setValueByPath (object, path, value) {Consequences
- Read Application Data, Modify Application Data: This weakness is usually exploited by using a special attribute of objects called proto, constructor, or prototype. Such attributes give access to the object prototype. An attacker can inject attributes that are used in other components by adding or modifying attributes of an object prototype. This creates attributes that exist on every object, or replace critical attributes with malicious ones. This can be problematic if the product depends on existence or non-existence of certain attributes, or uses pre-defined attributes of the object prototype (such as hasOwnProperty, toString, or valueOf).
- DoS: Crash, Exit, or Restart: An attacker can override existing attributes with ones that have incompatible type, which may lead to a crash.
Mitigations
- Implementation: By freezing the object prototype first (for example, Object.freeze(Object.prototype)), modification of the prototype becomes impossible.
- Architecture and Design: By blocking modifications of attributes that resolve to object prototype, such as proto or prototype, this weakness can be mitigated.
- Implementation: When handling untrusted objects, validating using a schema can be used.
- Implementation: By using an object without prototypes (via Object.create(null) ), adding object prototype attributes by accessing the prototype via the special attributes becomes impossible, mitigating this weakness.
- Implementation: Map can be used instead of objects in most cases. If Map methods are used instead of object attributes, it is not possible to access the object prototype or modify it.
Where this fits in a TurboPentest engagement
This weakness is not covered by the automated black-box pentest. IntegSec pentesters cover it in a manual engagement.
Frequently asked questions
What is CWE-1321?
The product receives input from an upstream component that specifies attributes that are to be initialized or updated in an object, but it does not properly control modifications of attributes of the object prototype.
How do you find Prototype Pollution?
Prototype Pollution is a specific, narrowly defined instance of a broader pattern. Testers confirm it with targeted code review and a proof-of-concept input that exercises the exact code path this weakness describes.
What is the impact of CWE-1321?
Read Application Data, Modify Application Data: This weakness is usually exploited by using a special attribute of objects called proto, constructor, or prototype. Such attributes give access to the object prototype. An attacker can inject attributes that are used in other components by adding or modifying attributes of an object prototype. This creates attributes that exist on every object, or replace critical attributes with malicious ones. This can be problematic if the product depends on existence or non-existence of certain attributes, or uses pre-defined attributes of the object prototype (such as hasOwnProperty, toString, or valueOf). DoS: Crash, Exit, or Restart: An attacker can override existing attributes with ones that have incompatible type, which may lead to a crash.
Does TurboPentest test for Prototype Pollution?
This weakness is not covered by the automated black-box pentest. IntegSec pentesters cover it in a manual engagement.
Related CWEs
Written and reviewed by
Michel Chamberland - Founder & CEO, IntegSec
CISSP, OSCP, OSCE, CEH, GIAC, CCSK · 20+ years in offensive security
Michel has spent 20+ years on offensive security teams including IBM X-Force Red and Trustwave SpiderLabs, leading penetration tests, red team engagements, and breach response for Fortune 500 customers. He is the founder of IntegSec and the architect of TurboPentest.
Find these issues before an attacker does
TurboPentest runs an agentic AI pentest against your target and reports findings with proof, from $99 per target.
Start a pentest