CWE-493 缺少Final Modifier的关键公开变量

Critical Public Variable Without Final Modifier

结构: Simple

Abstraction: Variant

状态: Draft

被利用可能性: High

基本描述

The product has a critical public variable that is not final, which allows the variable to be modified to contain unexpected values.

扩展描述

If a field is non-final and public, it can be changed once the value is set by any function that has access to the class which contains the field. This could lead to a vulnerability if other parts of the program make assumptions about the contents of that field.

相关缺陷

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

  • cwe_Nature: ChildOf cwe_CWE_ID: 216 cwe_View_ID: 1000

适用平台

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

常见的影响

范围 影响 注释
Integrity Modify Application Data The object could potentially be tampered with.
Confidentiality Read Application Data The object could potentially allow the object to be read.

可能的缓解方案

Implementation

策略:

Declare all public fields as final when possible, especially if it is used to maintain internal state of an Applet or of classes used by an Applet. If a field must be public, then perform all appropriate sanity checks before accessing the field from your code.

示例代码

Suppose this WidgetData class is used for an e-commerce web site. The programmer attempts to prevent price-tampering attacks by setting the price of the widget using the constructor.

bad Java

public final class WidgetData extends Applet {
public float price;
...
public WidgetData(...) {
this.price = LookupPrice("MyWidgetType");
}
}

The price field is not final. Even though the value is set by the constructor, it could be modified by anybody that has access to an instance of WidgetData.

Assume the following code is intended to provide the location of a configuration file that controls execution of the application.

bad C++

public string configPath = "/etc/application/config.dat";

bad Java

public String configPath = new String("/etc/application/config.dat");

While this field is readable from any function, and thus might allow an information leak of a pathname, a more serious problem is that it can be changed by any function.

分类映射

映射的分类名 ImNode ID Fit Mapped Node Name
7 Pernicious Kingdoms Mobile Code: Non-Final Public Field
CLASP Failure to provide confidentiality for stored data
The CERT Oracle Secure Coding Standard for Java (2011) OBJ10-J Do not use public static nonfinal variables
Software Fault Patterns SFP28 Unexpected access points