Python Pickle/Shelve Extended Deserialization

Detects extended use of pickle, shelve, and marshal for deserializing untrusted data beyond basic patterns.

zakirkun Updated

File contents

Python Pickle Extended Deserialization

Overview

Beyond basic pickle.loads(), Python has several other insecure deserialization mechanisms:

  • shelve (backed by pickle)
  • marshal.loads() (bytecode deserialization)
  • pickletools
  • HTTP APIs passing pickled data in cookies or request bodies

Remediation

  • Replace with json, msgpack, or protobuf
  • If using shelve/pickle for caching, ensure data source is trusted and server-controlled
  • Never accept serialized Python objects from HTTP clients

zakirkun/ice-tea/tree/main/skills/deserialization/python-pickle-extended commit d6a9399221

Frequently asked questions

npx skillmds@latest add zakirkun/python-pickle-shelve-extended-deserialization