Cloneable Class Containing Sensitive Information

Draft Variant
Structure: Simple
Description

This vulnerability occurs when a class containing sensitive information, such as credentials or personal data, is made cloneable. Attackers can bypass normal initialization and access the sensitive data by creating a copy of the object.

Extended Description

When a class implements the Cloneable interface without proper safeguards, it effectively becomes an open book. The clone() method can create copies of the object without calling its constructor, allowing any other class in the application to duplicate instances and directly access their internal, sensitive fields. This bypasses any security checks or initialization logic you might have placed in the constructor. To prevent this, you should explicitly deny cloning for classes that handle sensitive data. You can achieve this by declaring a clone() method that throws a CloneNotSupportedException. This simple step ensures your object's internal state remains controlled and prevents unintended data exposure through object duplication.

Common Consequences 1
Scope: Access Control

Impact: 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.

Potential Mitigations 1
Phase: Implementation
If you do make your classes clonable, ensure that your clone method is final and throw super.clone().
Demonstrative Examples 1
The following example demonstrates the weakness.

Code Example:

Bad
Java
java
Make classes uncloneable by defining a clone function like:

Code Example:

Good
Java
java
References 1
The CLASP Application Security Process
Secure Software, Inc.
2005
ID: REF-18
Likelihood of Exploit

Medium

Applicable Platforms
Languages:
C++ : UndeterminedJava : UndeterminedC# : Undetermined
Modes of Introduction
Implementation
Taxonomy Mapping
  • CLASP
  • The CERT Oracle Secure Coding Standard for Java (2011)
  • Software Fault Patterns