Sending non-cloned mutable data as a return value may result in that data being altered or deleted by the calling function.
View on MITREIn 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.
Potentially data could be tampered with by another function which should not have been tampered with.
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.
No detection method information available for this CWE.
This class has a private list of patients, but provides a way to see the list :
While this code only means to allow reading of the patient list, the getPatients() method returns a reference to the class's original patient list instead of a reference to a copy of the list. Any caller of this method can arbitrarily modify the contents of the patient list even though it is a private member of the class.
No relationship information available for this CWE.
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.
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.
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.
CWE-375 commonly affects C, C++, Java and C#. Note that weaknesses are often language-agnostic patterns, so secure coding practices apply broadly.
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.