CWE-767 通过公开方法可访问到关键的私有数据

Access to Critical Private Variable via Public Method

结构: Simple

Abstraction: Variant

状态: Incomplete

被利用可能性: unkown

基本描述

The software 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.

相关缺陷

  • cwe_Nature: ChildOf cwe_CWE_ID: 668 cwe_View_ID: 1000 cwe_Ordinal: Primary

适用平台

Language: [{'cwe_Name': 'C++', 'cwe_Prevalence': 'Undetermined'}, {'cwe_Name': 'C#', 'cwe_Prevalence': 'Undetermined'}, {'cwe_Name': 'Java', 'cwe_Prevalence': 'Undetermined'}]

常见的影响

范围 影响 注释
['Integrity', 'Other'] ['Modify Application Data', 'Other']

可能的缓解方案

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.

示例代码

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

bad C++

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 Java

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.

Notes

分类映射

映射的分类名 ImNode ID Fit Mapped Node Name
CLASP Failure to protect stored data from modification
Software Fault Patterns SFP23 Exposed Data
SEI CERT Perl Coding Standard OOP31-PL Imprecise Do not access private variables or subroutines in other packages