CWE-498: Cloneable Class Containing Sensitive Information

Export to Word

Description

The code contains a class with sensitive data, but the class is cloneable. The data can then be accessed by cloning the class.

Extended 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.


ThreatScore

Threat Mapped score: 0.0

Industry: Finiancial

Threat priority: Unclassified


Observed Examples (CVEs)

Related Attack Patterns (CAPEC)

N/A


Attack TTPs

N/A

Modes of Introduction

Phase Note
Implementation N/A

Common Consequences

Potential Mitigations

Applicable Platforms


Demonstrative Examples

Intro: The following example demonstrates the weakness.

Body: Make classes uncloneable by defining a clone function like:

public class CloneClient { public CloneClient() //throws java.lang.CloneNotSupportedException { Teacher t1 = new Teacher("guddu","22,nagar road"); //... // Do some stuff to remove the teacher. Teacher t2 = (Teacher)t1.clone(); System.out.println(t2.name); } public static void main(String args[]) { new CloneClient(); } } class Teacher implements Cloneable { public Object clone() { try { return super.clone(); } catch (java.lang.CloneNotSupportedException e) { throw new RuntimeException(e.toString()); } } public String name; public String clas; public Teacher(String name,String clas) { this.name = name; this.clas = clas; } }

Notes

← Back to CWE list