Public cloneable() Method Without Final ('Object Hijack')
DraftVariant
Structure: Simple
Description
A class has a cloneable() method that is not declared final, which allows an object to be created without calling the constructor. This can cause the object to be in an unexpected state.
Common Consequences 1
Scope: IntegrityOther
Impact: Unexpected StateVaries by Context
Potential Mitigations 1
Phase: Implementation
Make the cloneable() method final.
Demonstrative Examples 2
In this example, a public class "BankAccount" implements the cloneable() method which declares "Object clone(string accountnumber)":
Code Example:
Bad
Java
java
In the example below, a clone() method is defined without being declared final.
Code Example:
Bad
Java
java
References 2
Seven Pernicious Kingdoms: A Taxonomy of Software Security Errors
Katrina Tsipenyuk, Brian Chess, and Gary McGraw
NIST Workshop on Software Security Assurance Tools Techniques and Metrics • NIST