JSON vs. Pickle security
json is more secure because it's fundamentally more limited. The only python types that a json document can encode are unicode
, int
, float
, NoneType
, bool
, list
and dict
. these are marshaled/unmarshalled in a basically trivial fashion that isn't vulnerable to code injection attacks.
Pickle's problem is that it will can invoke arbitrary Python code. See http://nadiana.com/python-pickle-insecure for details. The JSON parser only has to create strings, numbers, lists, dicts, and so on. It never creates user-defined classes, so it doesn't need to execute arbitrary Python.