Description
The product defines a public method that reads or modifies a private variable.
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.
Potential Impact
Integrity, Other
Modify Application Data, Other
Demonstrative Examples
private: float price;public: void changePrice(float newPrice) {price = newPrice;}public class Client {private int UID;public int PID;private String userName;public Client(String userName){PID = getDefaultProfileID();UID = mapUserNametoUID( userName );this.userName = userName;}public void setPID(int ID) {UID = ID;}}Mitigations & Prevention
Use class accessor and mutator methods appropriately. Perform validation when accepting data from a public method that is intended to modify a critical private variable. Also be sure that appropriate access controls are being applied when a public method interfaces with critical data.
Related Weaknesses
Taxonomy Mappings
- CLASP: — Failure to protect stored data from modification
- Software Fault Patterns: SFP23 — Exposed Data
- SEI CERT Perl Coding Standard: OOP31-PL — Do not access private variables or subroutines in other packages
Frequently Asked Questions
What is CWE-767?
CWE-767 (Access to Critical Private Variable via Public Method) is a software weakness identified by MITRE's Common Weakness Enumeration. It is classified as a Base-level weakness. The product defines a public method that reads or modifies a private variable.
How can CWE-767 be exploited?
Attackers can exploit CWE-767 (Access to Critical Private Variable via Public Method) to modify application data, other. This weakness is typically introduced during the Implementation phase of software development.
How do I prevent CWE-767?
Key mitigations include: Use class accessor and mutator methods appropriately. Perform validation when accepting data from a public method that is intended to modify a critical private variable. Also be sure that appropriate
What is the severity of CWE-767?
CWE-767 is classified as a Base-level weakness (Medium abstraction). Its actual severity depends on the specific context and how the weakness manifests in your application.