CWE-375
Returning a Mutable Object to an Untrusted Caller
Description
The code sends non-cloned mutable data as a return value may result in that data being altered or deleted by the calling function.
Consequences
Access Control, Integrity
—
Modify Memory
The muitable data could be altered or deleted by the calling function. If this data was not previously cloned, the class will then be using modified data which may violate assumptions about its internal state.
Mitigations
Phase: Implementation
Declare returned data which should not be altered as constant or immutable.
Phase: Implementation
Clone all mutable data before returning references to it. This is the preferred mitigation. This way, regardless of what changes are made to the data, a valid copy is retained for use by the class.