Insecure Deserialization
Description
Insecure deserialization occurs when untrusted data is used to abuse the logic of an application, inflict a denial of service (DoS) attack, or even execute arbitrary code when data is deserialized.
Example with Scenario
Scenario: A web application accepts serialized objects from users and deserializes them on the server without proper validation. An attacker could craft a malicious serialized object that, when deserialized, executes arbitrary code or alters the application's behavior.
Payloads and Test Cases
Payloads
Java:
PHP:
Python:
Ruby:
Test Cases
Java:
Payload:
Test Case:
PHP:
Payload:
Test Case:
Python:
Payload:
Test Case:
Ruby:
Payload:
Test Case:
Mitigation
Validation and Filtering:
Validate and filter all input data, especially before deserialization.
Use a strict schema to validate serialized data.
Use Safe Libraries:
Use libraries and frameworks that provide secure methods for serialization and deserialization.
Avoid using native serialization if safer alternatives are available.
Implement Integrity Checks:
Implement integrity checks like digital signatures to ensure that the data has not been tampered with.
Use HMACs to verify data integrity.
Deserialization Controls:
Implement controls to restrict the types of objects that can be deserialized.
Use allow-lists to restrict acceptable classes during deserialization.
Monitor and Log:
Implement logging and monitoring to detect and respond to suspicious deserialization attempts.
Use intrusion detection systems (IDS) to alert on unusual deserialization activities.
Last updated