CWE-375

Returning a Mutable Object to an Untrusted Caller

Medium

Description

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

Potential Impact

How to Fix

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.

Related Weaknesses

References

View on MITRE CWE Database →

Need Help Fixing This Vulnerability?

Our security experts can help you identify and remediate CWE-375 vulnerabilities in your codebase.

Get Security Assessment