CWE-767: Access to Critical Private Variable via Public Method
Description
The product defines a public method that reads or modifies a private variable.
Submission Date :
March 3, 2009, midnight
Modification Date :
2023-06-29 00:00:00+00:00
Organization :
MITRE
Extended Description
If an attacker modifies the variable to contain unexpected values, this could violate assumptions from other parts of the code. Additionally, if an attacker can read the private variable, it may expose sensitive information or make it easier to launch further attacks.
Example - 1
The following example declares a critical variable to be private, and then allows the variable to be modified by public methods.
price = newPrice;private: float price;public: void changePrice(float newPrice) {}
Example - 2
The following example could be used to implement a user forum where a single user (UID) can switch between multiple profiles (PID).
PID = getDefaultProfileID();UID = mapUserNametoUID( userName );this.userName = userName;
UID = ID;private int UID;public int PID;private String userName;public Client(String userName){}public void setPID(int ID) {}public class Client {}
The programmer implemented setPID with the intention of modifying the PID variable, but due to a typo. accidentally specified the critical variable UID instead. If the program allows profile IDs to be between 1 and 10, but a UID of 1 means the user is treated as an admin, then a user could gain administrative privileges as a result of this typo.
Related Weaknesses
This table shows the weaknesses and high level categories that are related to this weakness. These relationships are defined to give an overview of the different insight to similar items that may exist at higher and lower levels of abstraction.
Visit http://cwe.mitre.org/ for more details.