CWE Database
/

CWE-375

Back to CWE list

CWE-375

Returning a Mutable Object to an Untrusted Caller

Base
Draft

Description

Sending non-cloned mutable data as a return value may result in that data being altered or deleted by the calling function.

In situations where functions return references to mutable data, it is possible that the external code which called the function may make changes to the data sent. If this data was not previously cloned, the class will then be using modified data which may violate assumptions about its internal state.

Common Consequences

Scope

Access Control
Integrity

Impact

Modify Memory

Potential Mitigations

Implementation

Declare returned data which should not be altered as constant or immutable.

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.

Applicable Platforms

Object-Oriented
C
C++
Java
C#

Security Training

Train your team to recognize and prevent security threats with our comprehensive security awareness program.

Start Training

Vulnerability Scanning

Discover vulnerabilities in your applications and infrastructure before attackers do.

Scan Now