The code contains a class with sensitive data, but the class is cloneable. The data can then be accessed by cloning the class.
View on MITRECloneable 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.
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().
No detection method information available for this CWE.
The following example demonstrates the weakness.
Make classes uncloneable by defining a clone function like:
The following example demonstrates the weakness.
Make classes uncloneable by defining a clone function like:
No relationship information available for this CWE.
CWE-498: Cloneable Class Containing Sensitive Information is a Common Weakness Enumeration (CWE) entry maintained by MITRE. 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.
If exploited, CWE-498 (Cloneable Class Containing Sensitive Information) it can compromise Access Control, leading to outcomes such as Bypass Protection Mechanism.
Recommended mitigations for CWE-498 include: If you do make your classes clonable, ensure that your clone method is final and throw super.clone().
CWE-498 commonly affects C++, Java and C#. Note that weaknesses are often language-agnostic patterns, so secure coding practices apply broadly.
A CWE (Common Weakness Enumeration) like CWE-498 describes a category of software weakness — the underlying flaw type. A CVE (Common Vulnerabilities and Exposures) identifies a specific, real-world vulnerability in a particular product. In short, a CWE is the kind of mistake, and a CVE is an instance of that mistake being found in software.