
Prevent Data Leakage and Trusted Field Clobbering ¶ Content-type header of an HTTP response set to application/x-java-serialized-object.If the captured traffic data includes the following patterns, it may suggest that the data was sent in Java serialization streams:

XStream with fromXML method (xstream version <= v1.4.6 is vulnerable to the serialization issue)Ĥ. Uses of readObject, readObjectNoData, readResolve or readExternal XMLdecoder with external user defined parametersĢ. Note that this addresses " billion laughs" type attacks by checking input length and number of objects deserialized.īe aware of the following Java API uses for potential serialization vulnerability.ġ. Use a safe replacement for the generic readObject() method as seen here.This safe behavior can be wrapped in a library like SerialKiller. In your code, override the ObjectInputStream#resolveClass() method to prevent arbitrary classes from being deserialized.The following techniques are all good for preventing attacks against deserialization against Java's Serializable format. Uses of jsonpickle with encode or store methods.Import yaml document = "!!python/object/apply:os.system " print ( yaml. The uses of pickle/c_pickle/_pickle with load/loads:.The following API in Python will be vulnerable to serialization attack. at the end, it's very likely that the data was sent in serialization. If the traffic data contains the symbol dot. Use a safe, standard data interchange format such as JSON (via json_decode() and json_encode()) if you need to pass serialized data to the user. PHP ¶ WhiteBox Review ¶Ĭheck the use of unserialize() function and review how the external parameters are accepted. The following language-specific guidance attempts to enumerate safe methodologies for deserializing data that can't be trusted. Guidance on Deserializing Objects Safely ¶
Serialization code#
Attacks against deserializers have been found to allow denial-of-service, access control, or remote code execution (RCE) attacks. Unfortunately, the features of these native deserialization mechanisms can sometimes be repurposed for malicious effect when operating on untrusted data. These native formats usually offer more features than JSON or XML, including customizability of the serialization process. However, many programming languages have native ways to serialize objects.

Today, the most popular data format for serializing data is JSON. People often serialize objects in order to save them for storage, or to send as part of communications.ĭeserialization is the reverse of that process, taking data structured in some format, and rebuilding it into an object. Serialization is the process of turning some object into a data format that can be restored later. This article is focused on providing clear, actionable guidance for safely deserializing untrusted data in your applications. Insecure Direct Object Reference Preventionĭeserialization Cheat Sheet ¶ Introduction ¶ Language-Agnostic Methods for Deserializing Safely Harden All java.io.ObjectInputStream Usage with an Agent Harden Your Own java.io.ObjectInputStream Prevent Deserialization of Domain Objects Prevent Data Leakage and Trusted Field Clobbering
