Weakness · Medium

CWE-374: Passing Mutable Objects to an Untrusted Method

What it is

The product sends non-cloned mutable data as an argument to a method or function.

Likelihood of exploit: MediumMITRE CWE 4.19.1

Severity (our rating)
Medium
Likelihood of exploit
Medium
Introduced during
Implementation
Exploited in the wild
No CVE in CISA's catalog

In more detail

The function or method that has been called can alter or delete the mutable data. This could violate assumptions that the calling function has made about its state. In situations where unknown code is called with references to mutable data, this external code could make changes to the data sent. If this data was not previously cloned, the modified data might not be valid in the context of execution.

What an attacker can do

  • Modify Memory (Integrity)

How to prevent it

Implementation

  • Pass in data which should not be altered as constant or immutable.
  • Clone all mutable data before passing it into an external function . 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-374 on MITRE's CWE site

H2 Security

Found it in your code?

We review where it appears, fix it with your team, and check it was not already used against you.

Talk to our team

T Academy

Stop writing it in the first place

Learn to build software and systems without weaknesses like this one, with practice on real hosts in your browser, every objective checked on the machine.

Start free

Source: MITRE Common Weakness Enumeration, CWE version 4.19.1. CWE is a trademark of The MITRE Corporation.