{"@ID": "766", "@Name": "Critical Data Element Declared Public", "@Abstraction": "Base", "@Structure": "Simple", "@Status": "Incomplete", "Description": "The product declares a critical variable, field, or member to be public when intended security policy requires it to be private.", "Related_Weaknesses": {"Related_Weakness": [{"@Nature": "ChildOf", "@CWE_ID": "732", "@View_ID": "1000", "@Ordinal": "Primary"}, {"@Nature": "ChildOf", "@CWE_ID": "1061", "@View_ID": "1000"}]}, "Weakness_Ordinalities": {"Weakness_Ordinality": [{"Ordinality": "Primary"}, {"Ordinality": "Indirect"}]}, "Applicable_Platforms": {"Language": [{"@Name": "C++", "@Prevalence": "Undetermined"}, {"@Name": "C#", "@Prevalence": "Undetermined"}, {"@Name": "Java", "@Prevalence": "Undetermined"}]}, "Modes_Of_Introduction": {"Introduction": {"Phase": "Implementation"}}, "Common_Consequences": {"Consequence": [{"Scope": ["Integrity", "Confidentiality"], "Impact": ["Read Application Data", "Modify Application Data"], "Note": "Making a critical variable public allows anyone with access to the object in which the variable is contained to alter or read the value."}, {"Scope": "Other", "Impact": "Reduce Maintainability", "Note": "This issue makes it more difficult to maintain the product, which indirectly affects security by making it more difficult or time-consuming to find and/or fix vulnerabilities."}]}, "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": "Data should be private, static, and final whenever possible. This will assure that your code is protected by instantiating early, preventing access, and preventing tampering."}}, "Demonstrative_Examples": {"Demonstrative_Example": [{"Intro_Text": "The following example declares a critical variable public, making it accessible to anyone with access to the object in which it is contained.", "Example_Code": [{"@Nature": "Bad", "@Language": "C++", "xhtml:div": "public: char* password;", "#text_blocks": ["public: char* password;"]}, {"@Nature": "Good", "@Language": "C++", "xhtml:div": "private: char* password;", "#text_blocks": ["private: char* password;"]}], "Body_Text": ["Instead, the critical data should be declared private.", "Even though this example declares the password to be private, there are other possible issues with this implementation, such as the possibility of recovering the password from process memory (CWE-257)."]}, {"@Demonstrative_Example_ID": "DX-212", "Intro_Text": "The following example shows a basic user account class that includes member variables for the username and password as well as a public constructor for the class and a public method to authorize access to the user account.", "Example_Code": [{"@Nature": "Bad", "@Language": "C++", "xhtml:div": {"xhtml:br": [null, null, null, null], "xhtml:div": {"@style": "margin-left:1em;", "xhtml:div": {"xhtml:div": [{"@style": "margin-left:1em;", "xhtml:div": {"xhtml:br": null, "xhtml:div": {"@style": "margin-left:1em;", "xhtml:br": [null, null, null], "xhtml:div": {"@style": "margin-left:1em;", "#text": "ExitError(\"Invalid username or password\");"}, "#text": "if ((strlen(username) > MAX_USERNAME_LENGTH) ||(strlen(password) > MAX_PASSWORD_LENGTH)) {}strcpy(this->username, username);strcpy(this->password, password);"}, "#text": "UserAccount(char *username, char *password){}"}}, {"@style": "margin-left:1em;", "xhtml:div": {"xhtml:br": [null, null, null, null, null, null, null, null], "xhtml:div": [{"@style": "margin-left:1em;", "#text": "ExitError(\"Invalid username or password\");"}, {"@style": "margin-left:1em;", "#text": "return 0;"}, {"@style": "margin-left:1em;", "#text": "return 1;"}], "xhtml:i": ["// if the username and password in the input parameters are equal to", "// the username and password of this account class then authorize access", "// otherwise do not authorize access"], "#text": "if ((strlen(username) > MAX_USERNAME_LENGTH) ||(strlen(password) > MAX_PASSWORD_LENGTH)) {}\n                                 \n                                 \n                                 \n                                 \n                                 if (strcmp(this->username, username) ||strcmp(this->password, password))\n                                 \n                                 \n                                 else"}}], "xhtml:br": [null, null, null, null, null, null], "#text": "public:\n                           \n                           int authorizeAccess(char *username, char *password){}\n                           char username[MAX_USERNAME_LENGTH+1];char password[MAX_PASSWORD_LENGTH+1];"}}, "#text": "#define MAX_PASSWORD_LENGTH 15#define MAX_USERNAME_LENGTH 15\n                     class UserAccount{};"}, "#text_blocks": ["#define MAX_PASSWORD_LENGTH 15", "#define MAX_USERNAME_LENGTH 15", "class UserAccount", "{", "public:", "UserAccount(char *username, char *password)", "{", "if ((strlen(username) > MAX_USERNAME_LENGTH) ||", "(strlen(password) > MAX_PASSWORD_LENGTH)) {", "ExitError(\"Invalid username or password\");", "}", "strcpy(this->username, username);", "strcpy(this->password, password);", "}", "int authorizeAccess(char *username, char *password)", "{", "if ((strlen(username) > MAX_USERNAME_LENGTH) ||", "(strlen(password) > MAX_PASSWORD_LENGTH)) {", "ExitError(\"Invalid username or password\");", "}", "// if the username and password in the input parameters are equal to", "// the username and password of this account class then authorize access", "if (strcmp(this->username, username) ||", "strcmp(this->password, password))", "return 0;", "// otherwise do not authorize access", "else", "return 1;", "}", "char username[MAX_USERNAME_LENGTH+1];", "char password[MAX_PASSWORD_LENGTH+1];", "};"]}, {"@Nature": "Good", "@Language": "C++", "xhtml:div": {"xhtml:br": [null, null, null, null], "xhtml:div": [{"@style": "margin-left:1em;", "#text": "..."}, {"@style": "margin-left:1em;", "xhtml:br": null, "#text": "char username[MAX_USERNAME_LENGTH+1];char password[MAX_PASSWORD_LENGTH+1];"}], "#text": "class UserAccount{public:\n                     \n                     private:};"}, "#text_blocks": ["class UserAccount", "{", "public:", "...", "private:", "char username[MAX_USERNAME_LENGTH+1];", "char password[MAX_PASSWORD_LENGTH+1];", "};"]}], "Body_Text": "However, the member variables username and password are declared public and therefore will allow access and changes to the member variables to anyone with access to the object. These member variables should be declared private as shown below to prevent unauthorized access and changes."}]}, "Observed_Examples": {"Observed_Example": {"Reference": "CVE-2010-3860", "Description": "variables declared public allow remote read of system properties such as user name and home directory.", "Link": "https://www.cve.org/CVERecord?id=CVE-2010-3860"}}, "Taxonomy_Mappings": {"Taxonomy_Mapping": [{"@Taxonomy_Name": "CLASP", "Entry_Name": "Failure to protect stored data from modification"}, {"@Taxonomy_Name": "The CERT Oracle Secure Coding Standard for Java (2011)", "Entry_ID": "OBJ01-J", "Entry_Name": "Declare data members as private and provide accessible wrapper methods"}, {"@Taxonomy_Name": "Software Fault Patterns", "Entry_ID": "SFP28", "Entry_Name": "Unexpected access points"}, {"@Taxonomy_Name": "OMG ASCMM", "Entry_ID": "ASCMM-MNT-15"}]}, "References": {"Reference": {"@External_Reference_ID": "REF-960", "@Section": "ASCMM-MNT-15"}}, "Mapping_Notes": {"Usage": "Allowed", "Rationale": "This CWE entry is at the Base 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": "CWE Content Team", "Submission_Organization": "MITRE", "Submission_Date": "2009-03-03", "Submission_Version": "1.4", "Submission_ReleaseDate": "2009-05-27"}, "Modification": [{"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2009-12-28", "Modification_Version": "1.7", "Modification_ReleaseDate": "2009-12-28", "Modification_Comment": "updated Demonstrative_Examples"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2010-12-13", "Modification_Version": "1.11", "Modification_ReleaseDate": "2010-12-13", "Modification_Comment": "updated Observed_Examples"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2011-06-01", "Modification_Version": "1.13", "Modification_ReleaseDate": "2011-06-01", "Modification_Comment": "updated Common_Consequences, Relationships, Taxonomy_Mappings"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2012-05-11", "Modification_Version": "2.2", "Modification_ReleaseDate": "2012-05-15", "Modification_Comment": "updated Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2014-07-30", "Modification_Version": "2.8", "Modification_ReleaseDate": "2014-07-31", "Modification_Comment": "updated Relationships, Taxonomy_Mappings"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2017-11-08", "Modification_Version": "3.0", "Modification_ReleaseDate": "2017-11-08", "Modification_Comment": "updated Likelihood_of_Exploit, Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2019-01-03", "Modification_Version": "3.2", "Modification_ReleaseDate": "2019-01-03", "Modification_Comment": "updated Common_Consequences, Description, Name, References, Relationships, Taxonomy_Mappings, Weakness_Ordinalities"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2020-02-24", "Modification_Version": "4.0", "Modification_ReleaseDate": "2020-02-24", "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 Detection_Factors, References, Relationships, Time_of_Introduction, Type"}, {"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, Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2023-10-26", "Modification_Version": "4.13", "Modification_ReleaseDate": "2023-10-26", "Modification_Comment": "updated Observed_Examples"}, {"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": "2026-10-28", "Modification_Version": "5.0", "Modification_ReleaseDate": "2026-10-28", "Modification_Comment": "updated Common_Consequences, Description"}], "Previous_Entry_Name": {"@Date": "2019-01-03", "#text": "Critical Variable Declared Public"}}, "entry_type": "Weakness"}
