CWE-375: Returning a Mutable Object to an Untrusted Caller

BaseDraftExploit Likelihood: Medium

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

View on MITRE
Back to CWE Lookup

Extended Description

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.

Technical Details

Structure
Simple

Applicable To

Languages
CC++JavaC#
Platforms

Frequently Asked Questions

What is CWE-375: Returning a Mutable Object to an Untrusted Caller?+

CWE-375: Returning a Mutable Object to an Untrusted Caller is a Common Weakness Enumeration (CWE) entry maintained by MITRE. 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.

What are the security consequences of Returning a Mutable Object to an Untrusted Caller?+

If exploited, CWE-375 (Returning a Mutable Object to an Untrusted Caller) it can compromise Access Control and Integrity, leading to outcomes such as Modify Memory.

How do you prevent or mitigate Returning a Mutable Object to an Untrusted Caller?+

Recommended mitigations for CWE-375 include: Declare returned data which should not be altered as constant or immutable. 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.

Which programming languages are affected by Returning a Mutable Object to an Untrusted Caller?+

CWE-375 commonly affects C, C++, Java and C#. Note that weaknesses are often language-agnostic patterns, so secure coding practices apply broadly.

What is the difference between a CWE and a CVE?+

A CWE (Common Weakness Enumeration) like CWE-375 describes a category of software weakness — the underlying flaw type. A CVE (Common Vulnerabilities and Exposures) identifies a specific, real-world vulnerability in a particular product. In short, a CWE is the kind of mistake, and a CVE is an instance of that mistake being found in software.

Learn More