CWE-502 Detail

CWE-502

Deserialization of Untrusted Data
MEDIUM
Draft
2006-07-19 00:00 +00:00
2023-06-29 00:00 +00:00

Alerte pour un CWE

Stay informed of any changes for a specific CWE.
Alert management

Deserialization of Untrusted Data

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

Extended Description

It is often convenient to serialize objects for communication or to save them for later use. However, deserialized data or code can often be modified without using the provided accessor functions if it does not use cryptography to protect itself. Furthermore, any cryptography would still be client-side security -- which is a dangerous security assumption.

Data that is untrusted can not be trusted to be well-formed.

When developers place no restrictions on "gadget chains," or series of instances and method invocations that can self-execute during the deserialization process (i.e., before the object is returned to the caller), it is sometimes possible for attackers to leverage them to perform unauthorized actions, like generating a shell.

Informations

Background Details

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").

Modes Of Introduction

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

Applicable Platforms

Language

Name: Java (Undetermined)
Name: Ruby (Undetermined)
Name: PHP (Undetermined)
Name: Python (Undetermined)
Name: JavaScript (Undetermined)

Technologies

Class: ICS/OT (Often)

Common Consequences

Scope Impact Likelihood
IntegrityModify Application Data, Unexpected State

Note: Attackers can modify unexpected objects or data that was assumed to be safe from modification.
AvailabilityDoS: Resource Consumption (CPU)

Note: If a function is making an assumption on when to terminate, based on a sentry in a string, it could easily never terminate.
OtherVaries by Context

Note: 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.

Observed Examples

Reference Description
CVE-2019-12799chain: bypass of untrusted deserialization issue (CWE-502) by using an assumed-trusted class (CWE-183)
CVE-2015-8103Deserialization issue in commonly-used Java library allows remote execution.
CVE-2015-4852Deserialization issue in commonly-used Java library allows remote execution.
CVE-2013-1465Use of PHP unserialize function on untrusted input allows attacker to modify application configuration.
CVE-2012-3527Use of PHP unserialize function on untrusted input in content management system might allow code execution.
CVE-2012-0911Use of PHP unserialize function on untrusted input in content management system allows code execution using a crafted cookie value.
CVE-2012-0911Content management system written in PHP allows unserialize of arbitrary objects, possibly allowing code execution.
CVE-2011-2520Python script allows local users to execute code via pickled data.
CVE-2012-4406Unsafe deserialization using pickle in a Python script.
CVE-2003-0791Web browser allows execution of native methods via a crafted string to a JavaScript function that deserializes the string.

Potential Mitigations

Phases : 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.
Phases : 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.
Phases : Implementation
Explicitly define a final object() to prevent deserialization.
Phases : 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.


Phases : Implementation
Avoid having unnecessary types or gadgets 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.

Detection Methods

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.)
Effectiveness : High

Vulnerability Mapping Notes

Rationale : 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.
Comments : 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.

Related Attack Patterns

CAPEC-ID Attack Pattern Name
CAPEC-586 Object Injection
An adversary attempts to exploit an application by injecting additional, malicious content during its processing of serialized objects. Developers leverage serialization in order to convert data or state into a static, binary format for saving to disk or transferring over a network. These objects are then deserialized when needed to recover the data/state. By injecting a malformed object into a vulnerable application, an adversary can potentially compromise the application by manipulating the deserialization process. This can result in a number of unwanted outcomes, including remote code execution.

Notes

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.

References

REF-18

The CLASP Application Security Process
Secure Software, Inc..
https://cwe.mitre.org/documents/sources/TheCLASPApplicationSecurityProcess.pdf

REF-461

Exploiting Deserialization Vulnerabilities in Java
Matthias Kaiser.
https://www.slideshare.net/codewhitesec/exploiting-deserialization-vulnerabilities-in-java-54707478

REF-462

PHP unserialization vulnerabilities: What are we missing?
Sam Thomas.
https://www.slideshare.net/_s_n_t/php-unserialization-vulnerabilities-what-are-we-missing

REF-463

Marshalling Pickles: How deserializing objects can ruin your day
Gabriel Lawrence, Chris Frohoff.
https://www.slideshare.net/frohoff1/appseccali-2015-marshalling-pickles

REF-464

Unserializing user-supplied data, a bad idea
Heine Deelstra.
https://drupalsun.com/heine/2010/08/25/unserializing-user-supplied-data-bad-idea

REF-465

Black Hat EU 2010 - Attacking Java Serialized Communication
Manish S. Saindane.
https://www.slideshare.net/msaindane/black-hat-eu-2010-attacking-java-serialized-communication

REF-466

Why Python Pickle is Insecure
Nadia Alramli.
http://michael-rushanan.blogspot.com/2012/10/why-python-pickle-is-insecure.html

REF-467

Exploiting misuse of Python's "pickle"
Nelson Elhage.
https://blog.nelhage.com/2011/03/exploiting-pickle/

REF-468

Deserialize My Shorts: Or How I Learned to Start Worrying and Hate Java Object Deserialization
Chris Frohoff.
https://speakerdeck.com/frohoff/owasp-sd-deserialize-my-shorts-or-how-i-learned-to-start-worrying-and-hate-java-object-deserialization

Submission

Name Organization Date Date Release Version
CLASP 2006-07-19 +00:00 2006-07-19 +00:00 Draft 3

Modifications

Name Organization Date Comment
Eric Dalci Cigital 2008-07-01 +00:00 updated Time_of_Introduction
CWE Content Team MITRE 2008-09-08 +00:00 updated Common_Consequences, Description, Relationships, Other_Notes, Taxonomy_Mappings
CWE Content Team MITRE 2009-10-29 +00:00 updated Description, Other_Notes, Potential_Mitigations
CWE Content Team MITRE 2011-06-01 +00:00 updated Common_Consequences, Relationships, Taxonomy_Mappings
CWE Content Team MITRE 2012-05-11 +00:00 updated Relationships, Taxonomy_Mappings
CWE Content Team MITRE 2012-10-30 +00:00 updated Demonstrative_Examples
CWE Content Team MITRE 2013-02-21 +00:00 updated Alternate_Terms, Applicable_Platforms, Background_Details, Common_Consequences, Maintenance_Notes, Observed_Examples, Potential_Mitigations, References, Relationships
CWE Content Team MITRE 2014-07-30 +00:00 updated Relationships, Taxonomy_Mappings
CWE Content Team MITRE 2015-12-07 +00:00 updated Observed_Examples, References, Relationships
CWE Content Team MITRE 2017-05-03 +00:00 updated Applicable_Platforms, Demonstrative_Examples, Description, Potential_Mitigations, References
CWE Content Team MITRE 2017-11-08 +00:00 updated Applicable_Platforms, Common_Consequences, Demonstrative_Examples, Modes_of_Introduction, Potential_Mitigations, References, Relationships
CWE Content Team MITRE 2018-03-27 +00:00 updated Relationships
CWE Content Team MITRE 2019-01-03 +00:00 updated Related_Attack_Patterns, Relationships, Taxonomy_Mappings
CWE Content Team MITRE 2019-06-20 +00:00 updated Type
CWE Content Team MITRE 2019-09-19 +00:00 updated Relationships
CWE Content Team MITRE 2020-02-24 +00:00 updated Observed_Examples, References, Relationships
CWE Content Team MITRE 2020-06-25 +00:00 updated Alternate_Terms, Potential_Mitigations
CWE Content Team MITRE 2020-08-20 +00:00 updated Relationships
CWE Content Team MITRE 2020-12-10 +00:00 updated Relationships
CWE Content Team MITRE 2021-07-20 +00:00 updated Relationships
CWE Content Team MITRE 2021-10-28 +00:00 updated Relationships
CWE Content Team MITRE 2022-06-28 +00:00 updated Relationships
CWE Content Team MITRE 2022-10-13 +00:00 updated Applicable_Platforms
CWE Content Team MITRE 2023-01-31 +00:00 updated Description
CWE Content Team MITRE 2023-04-27 +00:00 updated Detection_Factors, References, Relationships
CWE Content Team MITRE 2023-06-29 +00:00 updated Mapping_Notes, Relationships
Click on the button to the left (OFF), to authorize the inscription of cookie improving the functionalities of the site. Click on the button to the left (Accept all), to unauthorize the inscription of cookie improving the functionalities of the site.