CWE-498: Cloneable Class Containing Sensitive Information
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 MITREExtended Description
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.
Technical Details
- Structure
- Simple
Applicable To
Security Consequences
Scope
Impact
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.
Mitigation Strategies
Phase
Description
If you do make your classes clonable, ensure that your clone method is final and throw super.clone().
Detection Methods
No detection method information available for this CWE.
Code Examples & CVEs
Demonstrative Examples
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:
CWE Relationships
No relationship information available for this CWE.
Frequently Asked Questions
What is CWE-498: Cloneable Class Containing Sensitive Information?+
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.
What are the security consequences of Cloneable Class Containing Sensitive Information?+
If exploited, CWE-498 (Cloneable Class Containing Sensitive Information) it can compromise Access Control, leading to outcomes such as Bypass Protection Mechanism.
How do you prevent or mitigate Cloneable Class Containing Sensitive Information?+
Recommended mitigations for CWE-498 include: If you do make your classes clonable, ensure that your clone method is final and throw super.clone().
Which programming languages are affected by Cloneable Class Containing Sensitive Information?+
CWE-498 commonly affects C++, Java and C#. Note that weaknesses are often language-agnostic patterns, so secure coding practices apply broadly.
What is the difference between a CWE and a CVE?+
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.