BaseDraft

CWE-375Returning a Mutable Object to an Untrusted Caller

Category: other

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· 1

  • Access Control / Integrity — Modify Memory
    Potentially data could be tampered with by another function which should not have been tampered with.

Potential mitigations· 2

  • [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.

References

  1. https://cwe.mitre.org/data/definitions/375.html

Related by meaning· 6

Nearest entities by semantic similarity across the cs-graph corpus.

CWE
Passing Mutable Objects to an Untrusted Method
CWE
Cloneable Class Containing Sensitive Information
CWE
Private Data Structure Returned From A Public Method
CWE
Public cloneable() Method Without Final ('Object Hijack')
CWE
Public Static Final Field References Mutable Object
CWE
Serializable Class Containing Sensitive Data
Sourced from MITRE CWE 4.20. Curated for EU compliance use cases by Adam Lundqvist, Founder at SQUR.