Access to Critical Private Variable via Public Method

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


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.

Demonstrations

The following examples help to illustrate the nature of this weakness and describe methods or techniques which can be used to mitigate the risk.

Note that the examples here are by no means exhaustive and any given weakness may have many subtle varieties, each of which may require different detection methods or runtime controls.

Example One

The following example declares a critical variable to be private, and then allows the variable to be modified by public methods.

private: float price;
public: void changePrice(float newPrice) {
  price = newPrice;
}

Example Two

The following example could be used to implement a user forum where a single user (UID) can switch between multiple profiles (PID).

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.

See Also

SFP Secondary Cluster: Exposed Data

This category identifies Software Fault Patterns (SFPs) within the Exposed Data cluster (SFP23).

Permission Issues

Weaknesses in this category are related to improper assignment or handling of permissions.

Comprehensive CWE Dictionary

This view (slice) covers all the elements in CWE.

Weaknesses Introduced During Implementation

This view (slice) lists weaknesses that can be introduced during implementation.

Weaknesses Introduced During Design

This view (slice) lists weaknesses that can be introduced during design.


Common Weakness Enumeration content on this website is copyright of The MITRE Corporation unless otherwise specified. Use of the Common Weakness Enumeration and the associated references on this website are subject to the Terms of Use as specified by The MITRE Corporation.