结构: Simple
Abstraction: Variant
状态: Draft
被利用可能性: unkown
The product has a method that is declared public, but returns a reference to a private data structure, which could then be modified in unexpected ways.
Language: [{'cwe_Name': 'C', 'cwe_Prevalence': 'Undetermined'}, {'cwe_Name': 'C++', 'cwe_Prevalence': 'Undetermined'}, {'cwe_Name': 'Java', 'cwe_Prevalence': 'Undetermined'}, {'cwe_Name': 'C#', 'cwe_Prevalence': 'Undetermined'}]
范围 | 影响 | 注释 |
---|---|---|
Integrity | Modify Application Data | The contents of the data structure can be modified from outside the intended scope. |
策略:
Declare the method private.
策略:
Clone the member data and keep an unmodified version of the data private to the object.
策略:
Use public setter methods that govern how a private member can be modified.
Here, a public method in a Java class returns a reference to a private array. Given that arrays in Java are mutable, any modifications made to the returned reference would be reflected in the original private array.
bad Java
In this example, the Color class defines functions that return non-const references to private members (an array type and an integer type), which are then arbitrarily altered from outside the control of the class.
bad C++
映射的分类名 | ImNode ID | Fit | Mapped Node Name |
---|---|---|---|
7 Pernicious Kingdoms | Private Array-Typed Field Returned From A Public Method | ||
Software Fault Patterns | SFP23 | Exposed Data |