[Python-ideas] Adding a safe alternative to pickle in the standard library

Devin Jeanpierre jeanpierreda at gmail.com
Fri Feb 22 19:14:16 CET 2013


On Fri, Feb 22, 2013 at 12:41 PM, Andrew Barnert <abarnert at yahoo.com> wrote:
> The difference is that json.loads is just deserialize(foo), which pickle.loads inherently has some eval mixed in.
>
> That's why I think for most use cases, the answer is making json easier to extend, not making pickle easier to secure.

My original suggestion was to add a third thing, such as cerealizer,
not to restrict pickle or extend json. Some others have talked about
restricting pickle, but I don't know how one could do that and still
be confident in the safety of the end product. You usually build
things to be safe from the ground up, not as some afterthought with a
few restrictions.

> The biggest problem people have with the json library isn't that you have to do the extending explicitly and externally, but that it's a huge pain to do so. There was a suggestion earlier in this thread (I forget the author) that would go a long way toward relieving that pain.

I feel that'd be very helpful, yes. Obviously not as helpful as
something that can handle cyclic references, but those aren't really
as important. Besides which, a yaml module could synthesize something
more complete out of these pieces (YAML is like JSON, but with support
for cyclic references and some extra syntax).

My issue is making safe serialization easier, so that not using pickle
is a viable option. As you say, we can go a long way towards this
using the json module.

-- Devin



More information about the Python-ideas mailing list