{"@ID": "1321", "@Name": "Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution')", "@Abstraction": "Variant", "@Structure": "Simple", "@Status": "Incomplete", "@Diagram": "/data/images/CWE-1321-Diagram.png", "Description": "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.", "Related_Weaknesses": {"Related_Weakness": [{"@Nature": "ChildOf", "@CWE_ID": "915", "@View_ID": "1000", "@Ordinal": "Primary"}, {"@Nature": "ChildOf", "@CWE_ID": "913", "@View_ID": "1003", "@Ordinal": "Primary"}, {"@Nature": "CanPrecede", "@CWE_ID": "471", "@View_ID": "1000", "@Ordinal": "Primary"}]}, "Weakness_Ordinalities": {"Weakness_Ordinality": {"Ordinality": "Primary"}}, "Applicable_Platforms": {"Language": {"@Name": "JavaScript", "@Prevalence": "Undetermined"}}, "Modes_Of_Introduction": {"Introduction": [{"Phase": "Architecture and Design"}, {"Phase": "Implementation", "Note": "This weakness is often found in code that assigns object attributes based on user input, or merges or clones objects recursively."}]}, "Common_Consequences": {"Consequence": [{"Scope": ["Confidentiality", "Integrity", "Availability"], "Impact": ["Read Application Data", "Modify Application Data"], "Likelihood": "High", "Note": "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)."}, {"Scope": "Availability", "Impact": "DoS: Crash, Exit, or Restart", "Likelihood": "High", "Note": "An attacker can override existing attributes with ones that have incompatible type, which may lead to a crash."}]}, "Detection_Methods": {"Detection_Method": {"@Detection_Method_ID": "DM-14", "Method": "Automated Static Analysis", "Description": "Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect \"sources\" (origins of input) with \"sinks\" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)", "Effectiveness": "High"}}, "Potential_Mitigations": {"Mitigation": [{"Phase": "Implementation", "Description": "By freezing the object prototype first (for example, Object.freeze(Object.prototype)), modification of the prototype becomes impossible.", "Effectiveness": "High", "Effectiveness_Notes": "While this can mitigate this weakness completely, other methods are recommended when possible, especially in components used by upstream software (\"libraries\")."}, {"Phase": "Architecture and Design", "Description": "By blocking modifications of attributes that resolve to object prototype, such as proto or prototype, this weakness can be mitigated.", "Effectiveness": "High"}, {"Phase": "Implementation", "Strategy": "Input Validation", "Description": "When handling untrusted objects, validating using a schema can be used.", "Effectiveness": "Limited"}, {"Phase": "Implementation", "Description": "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.", "Effectiveness": "High"}, {"Phase": "Implementation", "Description": "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.", "Effectiveness": "Moderate"}]}, "Demonstrative_Examples": {"Demonstrative_Example": {"@Demonstrative_Example_ID": "DX-206", "Intro_Text": "This function sets object attributes based on a dot-separated path.", "Example_Code": [{"@Nature": "Bad", "@Language": "JavaScript", "xhtml:div": {"xhtml:br": null, "xhtml:div": {"@style": "margin-left:1em;", "xhtml:br": [null, null, null, null, null, null, null, null], "xhtml:div": {"@style": "margin-left:1em;", "xhtml:br": [null, null, null], "xhtml:div": {"@style": "margin-left:1em;", "xhtml:br": null, "#text": "objectToModify[attr] = {};\n\t\t\t\t\t        }"}, "#text": "if (typeof objectToModify[attr] !== 'object') {\n\t\t\t\t\t    \n\t\t\t\t\t        objectToModify = objectToModify[attr];\n\t\t\t\t\t    }"}, "#text": "const pathArray = path.split(\".\");\n\t\t\t\t\t    const attributeToSet = pathArray.pop();\n\t\t\t\t\t    let objectToModify = object;\n\t\t\t\t\t    for (const attr of pathArray) {\n\t\t\t\t\t    \n\t\t\t\t\t    objectToModify[attributeToSet] = value;\n\t\t\t\t\t    return object;\n\t\t\t\t\t}"}, "#text": "function setValueByPath (object, path, value) {"}}, {"@Nature": "Bad", "@Language": "JavaScript", "xhtml:div": {"xhtml:br": [null, null], "#text": "setValueByPath({}, \"__proto__.isAdmin\", true)\n\t\t\t\t\t  setValueByPath({}, \"constructor.prototype.isAdmin\", true)"}}, {"@Nature": "Good", "@Language": "JavaScript", "xhtml:div": {"xhtml:br": null, "xhtml:div": {"@style": "margin-left:1em;", "xhtml:br": [null, null, null, null, null, null, null], "xhtml:div": {"@style": "margin-left:1em;", "xhtml:i": "// Ignore attributes which resolve to object prototype", "xhtml:br": [null, null, null, null, null], "xhtml:div": [{"@style": "margin-left:1em;", "xhtml:br": [null, null], "#text": "continue;\n\t\t\t\t\t        }"}, {"@style": "margin-left:1em;", "xhtml:br": [null, null], "#text": "objectToModify[attr] = {};\n\t\t\t\t\t        }"}], "#text": "if (attr === \"__proto__\" || attr === \"constructor\" || attr === \"prototype\") {\n\t\t\t\t\t\n\t\t\t\t\t        if (typeof objectToModify[attr] !== \"object\") {\n\t\t\t\t\t\n\t\t\t\t\t        objectToModify = objectToModify[attr];\n\t\t\t\t\t    }"}, "#text": "const pathArray = path.split(\".\");\n\t\t\t\t\t    const attributeToSet = pathArray.pop();\n\t\t\t\t\t    let objectToModify = object;\n\t\t\t\t\t    for (const attr of pathArray) {\n\t\t\t\t\t\n\t\t\t\t\t    objectToModify[attributeToSet] = value;\n\t\t\t\t\t    return object;\n\t\t\t\t\t}"}, "#text": "function setValueByPath (object, path, value) {"}}], "Body_Text": ["This function does not check if the attribute resolves to the object prototype. These codes can be used to add \"isAdmin: true\" to the object prototype.", "By using a denylist of dangerous attributes, this weakness can be eliminated."]}}, "Observed_Examples": {"Observed_Example": [{"Reference": "CVE-2018-3721", "Description": "Prototype pollution by merging objects.", "Link": "https://www.cve.org/CVERecord?id=CVE-2018-3721"}, {"Reference": "CVE-2019-10744", "Description": "Prototype pollution by setting default values to object attributes recursively.", "Link": "https://www.cve.org/CVERecord?id=CVE-2019-10744"}, {"Reference": "CVE-2019-11358", "Description": "Prototype pollution by merging objects recursively.", "Link": "https://www.cve.org/CVERecord?id=CVE-2019-11358"}, {"Reference": "CVE-2020-8203", "Description": "Prototype pollution by setting object attributes based on dot-separated path.", "Link": "https://www.cve.org/CVERecord?id=CVE-2020-8203"}]}, "Related_Attack_Patterns": {"Related_Attack_Pattern": [{"@CAPEC_ID": "1"}, {"@CAPEC_ID": "180"}, {"@CAPEC_ID": "77"}]}, "References": {"Reference": [{"@External_Reference_ID": "REF-1148"}, {"@External_Reference_ID": "REF-1149"}]}, "Mapping_Notes": {"Usage": "Allowed", "Rationale": "This CWE entry is at the Variant level of abstraction, which is a preferred level of abstraction for mapping to the root causes of vulnerabilities.", "Comments": "Carefully read both the name and description to ensure that this mapping is an appropriate fit. Do not try to 'force' a mapping to a lower-level Base/Variant simply to comply with this preferred level of abstraction.", "Reasons": {"Reason": {"@Type": "Acceptable-Use"}}}, "Content_History": {"Submission": {"Submission_Name": "Anonymous External Contributor", "Submission_Date": "2020-08-25", "Submission_Version": "4.3", "Submission_ReleaseDate": "2020-12-10"}, "Modification": [{"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2021-10-28", "Modification_Version": "4.6", "Modification_ReleaseDate": "2021-10-28", "Modification_Comment": "updated Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2023-01-31", "Modification_Version": "4.10", "Modification_ReleaseDate": "2023-01-31", "Modification_Comment": "updated Description"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2023-04-27", "Modification_Version": "4.11", "Modification_ReleaseDate": "2023-04-27", "Modification_Comment": "updated Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2023-06-29", "Modification_Version": "4.12", "Modification_ReleaseDate": "2023-06-29", "Modification_Comment": "updated Mapping_Notes"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2024-02-29", "Modification_Version": "4.14", "Modification_ReleaseDate": "2024-02-29", "Modification_Comment": "updated Demonstrative_Examples"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2025-09-09", "Modification_Version": "4.18", "Modification_ReleaseDate": "2025-09-09", "Modification_Comment": "updated Common_Consequences, Description, Diagram, Modes_of_Introduction"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2025-12-11", "Modification_Version": "4.19", "Modification_ReleaseDate": "2025-12-11", "Modification_Comment": "updated Detection_Factors, Weakness_Ordinalities"}]}}
