security deserialization ai_generated true

Remote code execution — unsafe deserialization of untrusted data

ID: security/deserialization-rce-untrusted-input

Also available as: JSON · Markdown
88%Fix Rate
92%Confidence
4Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
any active

Root Cause

Using pickle or Java ObjectInputStream on untrusted input allows arbitrary code execution.

generic

Workarounds

  1. 95% success Replace unsafe deserializers with safe formats like JSON or Protobuf
    json.loads(data) instead of pickle.loads(data)

    Sources: https://docs.python.org/3/library/pickle.html#restricting-globals

  2. 78% success If pickle is required, use RestrictedUnpickler with strict class allowlist
    class SafeUnpickler(pickle.Unpickler): def find_class(self, module, name): ...

    Sources: https://docs.python.org/3/library/pickle.html#restricting-globals

Dead Ends

Common approaches that don't work:

  1. Validate the serialized data before deserializing 90% fail

    The exploit triggers during deserialization itself, not after

  2. Use a custom ObjectInputStream with class whitelist alone 65% fail

    Gadget chains can use allowed classes to achieve code execution