Before version 1.6, Django defaulted to using pickle
to serialize session data before storing it in the backend. If you're using the signed cookie session backend and SECRET_KEY
is known by an attacker (there isn't an inherent vulnerability in Django that would cause it to leak), the attacker could insert a string into their session which, when unpickled, executes arbitrary code on the server. The technique for doing so is simple and easily available on the internet.
Although the cookie session storage signs the cookie-stored data to prevent tampering, a SECRET_KEY
leak immediately escalates to a remote code execution vulnerability. This attack can be mitigated by serializing session data using JSON rather than pickle
. To facilitate this, Django 1.5.3 introduced a new setting, SESSION_SERIALIZER
, to customize the session serialization format. For backwards compatibility, this setting defaults to using django.contrib.sessions.serializers.PickleSerializer
in Django 1.5...