1 Why Deserialization is Dangerous
Deserialization converts a byte stream or string back into an object. When you deserialize attacker-controlled data, the deserialization process itself can execute arbitrary code — before any application logic runs.
# CRITICAL — never deserialize untrusted data with pickle
import pickle, base64
data = base64.b64decode(request.cookies['session'])
obj = pickle.loads(data) # RCE if data is malicious
Python's pickle, Java's native serialization, PHP's unserialize(), and Ruby's Marshal.load() are all capable of executing code during deserialization through magic methods (__reduce__, readObject, __wakeup).