Base · Medium

CWE-767: Access to Critical Private Variable via Public Method

The product defines a public method that reads or modifies a private variable.

CWE-767 · Base Level ·1 Mitigations

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

The following example declares a critical variable to be private, and then allows the variable to be modified by public methods.
Bad
private: float price;public: void changePrice(float newPrice) {price = newPrice;}
The following example could be used to implement a user forum where a single user (UID) can switch between multiple profiles (PID).
Bad
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;}}
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.

Mitigations & Prevention

Implementation

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.

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.