The product deserializes untrusted data without sufficiently ensuring that the resulting data will be valid.

Primary

Resultant

Serialization and deserialization refer to the process of taking program-internal object-related data, packaging it in a way that allows the data to be externally stored or transferred ("serialization"), then extracting the serialized data to reconstruct the original object ("deserialization").

Marshaling, Unmarshaling
Marshaling and unmarshaling are effectively synonyms for serialization and deserialization, respectively.

Pickling, Unpickling
In Python, the "pickle" functionality is used to perform serialization and deserialization.

PHP Object Injection
Some PHP application researchers use this term when attacking unsafe use of the unserialize() function; but it is also used for CWE-915.

Architecture and Design
OMISSION: This weakness is caused by missing a security tactic during the architecture and design phase.

Implementation

Medium

Integrity
Modify Application Data
Unexpected State
Attackers can modify unexpected objects or data that was assumed to be safe from modification. Deserialized data or code could be modified without using the provided accessor functions, or unexpected functions could be invoked.

Availability
DoS: Resource Consumption (CPU)
If a function is making an assumption on when to terminate, based on a sentry in a string, it could easily never terminate.

Other
Varies by Context
The consequences can vary widely, because it depends on which objects or methods are being deserialized, and how they are used. Making an assumption that the code in the deserialized object is valid is dangerous and can enable exploitation. One example is attackers using gadget chains to perform unauthorized actions, such as generating a shell.

Automated Static Analysis
Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)
High

Architecture and Design
Implementation
If available, use the signing/sealing features of the programming language to assure that deserialized data has not been tainted. For example, a hash-based message authentication code (HMAC) could be used to ensure that data has not been modified.

Implementation
When deserializing data, populate a new object rather than just deserializing. The result is that the data flows through safe input validation and that the functions are safe.

Implementation
Explicitly define a final object() to prevent deserialization.

Architecture and Design
Implementation

Make fields transient to protect them from deserialization.
An attempt to serialize and then deserialize a class containing transient fields will result in NULLs where the transient data should be. This is an excellent way to prevent time, environment-based, or sensitive variables from being carried over and used improperly.

Implementation
Avoid having unnecessary types or gadgets (a sequence of instances and method invocations that can self-execute during the deserialization process, often found in libraries) available that can be leveraged for malicious ends. This limits the potential for unintended or unauthorized types and gadgets to be leveraged by the attacker. Add only acceptable classes to an allowlist. Note: new gadgets are constantly being discovered, so this alone is not a sufficient mitigation.

Architecture and Design
Implementation
Employ cryptography of the data or code for protection. However, it's important to note that it would still be client-side security. This is risky because if the client is compromised then the security implemented on the client (the cryptography) can be bypassed.

Operation
Firewall
Use an application firewall that can detect attacks against this weakness. It can be beneficial in cases in which the code cannot be fixed (because it is controlled by a third party), as an emergency prevention measure while more comprehensive software assurance measures are applied, or to provide defense in depth [REF-1481].
Moderate
An application firewall might not cover all possible input vectors. In addition, attack techniques might be available to bypass the protection mechanism, such as using malformed inputs that can still be processed by the component that receives those inputs. Depending on functionality, an application firewall might inadvertently reject or modify legitimate requests. Finally, some manual effort may be required for customization.

This code snippet deserializes an object from a file and uses it as a UI button:

try {File file = new File("object.obj");ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));javax.swing.JButton button = (javax.swing.JButton) in.readObject();in.close();}

This code does not attempt to verify the source or contents of the file before deserializing it. An attacker may be able to replace the intended file with a file that contains arbitrary malicious code which will be executed when the button is pressed.
To mitigate this, explicitly define final readObject() to prevent deserialization. An example of this is:

private final void readObject(ObjectInputStream in) throws java.io.IOException {throw new java.io.IOException("Cannot be deserialized"); }

In Python, the Pickle library handles the serialization and deserialization processes. In this example derived from [REF-467], the code receives and parses data, and afterwards tries to authenticate a user based on validating a token.

try {
class ExampleProtocol(protocol.Protocol):def dataReceived(self, data):
# Code that would be here would parse the incoming data# After receiving headers, call confirmAuth() to authenticate
def confirmAuth(self, headers):try:token = cPickle.loads(base64.b64decode(headers['AuthToken']))if not check_hmac(token['signature'], token['data'], getSecretKey()):raise AuthFailself.secure_data = token['data']except:raise AuthFail
}

Unfortunately, the code does not verify that the incoming data is legitimate. An attacker can construct a illegitimate, serialized object "AuthToken" that instantiates one of Python's subprocesses to execute arbitrary commands. For instance,the attacker could construct a pickle that leverages Python's subprocess module, which spawns new processes and includes a number of arguments for various uses. Since Pickle allows objects to define the process for how they should be unpickled, the attacker can direct the unpickle process to call Popen in the subprocess module and execute /bin/sh.

CVE-2024-37052
insecure deserialization in platform for managing AI/ML applications and models allows code execution via a crafted pickled object in a model file
https://www.cve.org/CVERecord?id=CVE-2024-37052

CVE-2024-37288
deserialization of untrusted YAML data in dashboard for data query and visualization of Elasticsearch data
https://www.cve.org/CVERecord?id=CVE-2024-37288

CVE-2024-9314
PHP object injection in WordPress plugin for AI-based SEO
https://www.cve.org/CVERecord?id=CVE-2024-9314

CVE-2019-12799
chain: bypass of untrusted deserialization issue (CWE-502) by using an assumed-trusted class (CWE-183)
https://www.cve.org/CVERecord?id=CVE-2019-12799

CVE-2015-8103
Deserialization issue in commonly-used Java library allows remote execution.
https://www.cve.org/CVERecord?id=CVE-2015-8103

CVE-2015-4852
Deserialization issue in commonly-used Java library allows remote execution.
https://www.cve.org/CVERecord?id=CVE-2015-4852

CVE-2013-1465
Use of PHP unserialize function on untrusted input allows attacker to modify application configuration.
https://www.cve.org/CVERecord?id=CVE-2013-1465

CVE-2012-3527
Use of PHP unserialize function on untrusted input in content management system might allow code execution.
https://www.cve.org/CVERecord?id=CVE-2012-3527

CVE-2012-0911
Use of PHP unserialize function on untrusted input in content management system allows code execution using a crafted cookie value.
https://www.cve.org/CVERecord?id=CVE-2012-0911

CVE-2012-0911
Content management system written in PHP allows unserialize of arbitrary objects, possibly allowing code execution.
https://www.cve.org/CVERecord?id=CVE-2012-0911

CVE-2011-2520
Python script allows local users to execute code via pickled data.
https://www.cve.org/CVERecord?id=CVE-2011-2520

CVE-2012-4406
Unsafe deserialization using pickle in a Python script.
https://www.cve.org/CVERecord?id=CVE-2012-4406

CVE-2003-0791
Web browser allows execution of native methods via a crafted string to a JavaScript function that deserializes the string.
https://www.cve.org/CVERecord?id=CVE-2003-0791

Deserialization of untrusted data

SER01-J
Do not deviate from the proper signatures of serialization methods

SER03-J
Do not serialize unencrypted, sensitive data

SER06-J
Make defensive copies of private mutable components during deserialization

SER08-J
Do not use the default serialized form for implementation defined invariants

SFP25
Tainted input to variable

Allowed
This CWE entry is at the Base level of abstraction, which is a preferred level of abstraction for mapping to the root causes of vulnerabilities.
Carefully read both the name and description to ensure that this mapping is an appropriate fit. Do not try to 'force' a mapping to a lower-level Base/Variant simply to comply with this preferred level of abstraction.

The relationships between CWE-502 and CWE-915 need further exploration. CWE-915 is more narrowly scoped to object modification, and is not necessarily used for deserialization.

CLASP
2006-07-19
Draft 3
2006-07-19

Eric Dalci
Cigital
2008-07-01
updated Time_of_Introduction

CWE Content Team
MITRE
2008-09-08
updated Common_Consequences, Description, Relationships, Other_Notes, Taxonomy_Mappings

CWE Content Team
MITRE
2009-10-29
updated Description, Other_Notes, Potential_Mitigations

CWE Content Team
MITRE
2011-06-01
updated Common_Consequences, Relationships, Taxonomy_Mappings

CWE Content Team
MITRE
2012-05-11
updated Relationships, Taxonomy_Mappings

CWE Content Team
MITRE
2012-10-30
updated Demonstrative_Examples

CWE Content Team
MITRE
2013-02-21
updated Alternate_Terms, Applicable_Platforms, Background_Details, Common_Consequences, Maintenance_Notes, Observed_Examples, Potential_Mitigations, References, Relationships

CWE Content Team
MITRE
2014-07-30
updated Relationships, Taxonomy_Mappings

CWE Content Team
MITRE
2015-12-07
updated Observed_Examples, References, Relationships

CWE Content Team
MITRE
2017-05-03
updated Applicable_Platforms, Demonstrative_Examples, Description, Potential_Mitigations, References

CWE Content Team
MITRE
2017-11-08
updated Applicable_Platforms, Common_Consequences, Demonstrative_Examples, Modes_of_Introduction, Potential_Mitigations, References, Relationships

CWE Content Team
MITRE
2018-03-27
updated Relationships

CWE Content Team
MITRE
2019-01-03
updated Related_Attack_Patterns, Relationships, Taxonomy_Mappings

CWE Content Team
MITRE
2019-06-20
updated Type

CWE Content Team
MITRE
2019-09-19
updated Relationships

CWE Content Team
MITRE
2020-02-24
updated Observed_Examples, References, Relationships

CWE Content Team
MITRE
2020-06-25
updated Alternate_Terms, Potential_Mitigations

CWE Content Team
MITRE
2020-08-20
updated Relationships

CWE Content Team
MITRE
2020-12-10
updated Relationships

CWE Content Team
MITRE
2021-07-20
updated Relationships

CWE Content Team
MITRE
2021-10-28
updated Relationships

CWE Content Team
MITRE
2022-06-28
updated Relationships

CWE Content Team
MITRE
2022-10-13
updated Applicable_Platforms

CWE Content Team
MITRE
2023-01-31
updated Description

CWE Content Team
MITRE
2023-04-27
updated Detection_Factors, References, Relationships

CWE Content Team
MITRE
2023-06-29
updated Mapping_Notes, Relationships

CWE Content Team
MITRE
2024-11-19
4.16
2024-11-19
updated Common_Consequences, Description, Diagram, Potential_Mitigations, Relationships

CWE Content Team
MITRE
2025-09-09
4.18
2025-09-09
updated Observed_Examples, Potential_Mitigations, References

CWE Content Team
MITRE
2025-12-11
4.19
2025-12-11
updated Applicable_Platforms, Observed_Examples, Relationships, Weakness_Ordinalities

Abhi Balakrishnan
2024-02-29
4.16
2024-11-19
Contributed usability diagram concepts used by the CWE team