结构: Simple
Abstraction: Variant
状态: Draft
被利用可能性: Medium
The code contains a class with sensitive data, but the class is cloneable. The data can then be accessed by cloning the class.
Cloneable classes are effectively open classes, since data cannot be hidden in them. Classes that do not explicitly deny cloning can be cloned by any other class without running the constructor.
cwe_Nature: ChildOf cwe_CWE_ID: 664 cwe_View_ID: 1000 cwe_Ordinal: Primary
cwe_Nature: CanPrecede cwe_CWE_ID: 200 cwe_View_ID: 1000
cwe_Nature: CanPrecede cwe_CWE_ID: 200 cwe_View_ID: 699
Language: [{'cwe_Name': 'C++', 'cwe_Prevalence': 'Undetermined'}, {'cwe_Name': 'Java', 'cwe_Prevalence': 'Undetermined'}, {'cwe_Name': 'C#', 'cwe_Prevalence': 'Undetermined'}]
范围 | 影响 | 注释 |
---|---|---|
Access Control | Bypass Protection Mechanism | A class that can be cloned can be produced without executing the constructor. This is dangerous since the constructor may perform security-related checks. By allowing the object to be cloned, those checks may be bypassed. |
策略:
If you do make your classes clonable, ensure that your clone method is final and throw super.clone().
The following example demonstrates the weakness.
bad Java
Make classes uncloneable by defining a clone function like:
good Java
映射的分类名 | ImNode ID | Fit | Mapped Node Name |
---|---|---|---|
CLASP | Information leak through class cloning | ||
The CERT Oracle Secure Coding Standard for Java (2011) | OBJ07-J | Sensitive classes must not let themselves be copied | |
Software Fault Patterns | SFP23 | Exposed Data |