Python Pickle
Python's serialization module that can execute arbitrary code during deserialization, making it dangerous for untrusted input.
Python Pickle is Python's native serialization module that converts objects to byte streams and back. However, it can execute arbitrary code during deserialization, making it extremely dangerous for untrusted data.
__reduce__ Method
The __reduce__ method tells pickle how to reconstruct an object. It returns a callable and arguments; attackers abuse this to call dangerous functions.
Where Pickle Is Used
- Flask session cookies (if using pickle serializer)
- Celery task arguments
- Redis/memcached caching
- ML model serialization
- Django cache backend
Prevention
- Never unpickle untrusted data
- Use JSON or other safe formats
- Sign pickled data with HMAC
- Use
RestrictedUnpicklerto limit allowed classes