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 |
Integrity | Modify Application Data, Unexpected State
Note: 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)
Note: 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
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. One example is attackers using gadget chains to perform unauthorized actions, such as generating a shell. | |
Observed Examples
Reference |
Description |
CVE-2019-12799 | chain: bypass of untrusted deserialization issue (CWE-502) by using an assumed-trusted class (CWE-183) |
CVE-2015-8103 | Deserialization issue in commonly-used Java library allows remote execution. |
CVE-2015-4852 | Deserialization issue in commonly-used Java library allows remote execution. |
CVE-2013-1465 | Use of PHP unserialize function on untrusted input allows attacker to modify application configuration. |
CVE-2012-3527 | Use of PHP unserialize function on untrusted input in content management system might allow code execution. |
CVE-2012-0911 | Use of PHP unserialize function on untrusted input in content management system allows code execution using a crafted cookie value. |
CVE-2012-0911 | Content management system written in PHP allows unserialize of arbitrary objects, possibly allowing code execution. |
CVE-2011-2520 | Python script allows local users to execute code via pickled data. |
CVE-2012-4406 | Unsafe deserialization using pickle in a Python script. |
CVE-2003-0791 | Web 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 (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.
Phases : 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.
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 |
CWE Content Team |
MITRE |
2024-11-19 +00:00 |
updated Common_Consequences, Description, Diagram, Potential_Mitigations, Relationships |