<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 22, 2015 at 9:46 PM, Nathaniel Smith <span dir="ltr"><<a href="mailto:njs@pobox.com" target="_blank">njs@pobox.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Wed, Jul 22, 2015 at 5:27 PM, Neil Girdhar <<a href="mailto:mistersheik@gmail.com">mistersheik@gmail.com</a>> wrote:<br>
><br>
> That is so unfortunate.  Pickle is such a good solution except for the<br>
> security.  Why can't we have security too?  It doesn't seem to me to be<br>
> right for a project like matplotlib to be writing their own serialization<br>
> library.  It would be awesome if Python had secure serialization built-in.<br>
<br>
</span>The reason you can pickle/unpickle arbitrary Python objects is that<br>
the pickle format is basically a structured, optimized way of<br>
generating and then evaluating arbitrary Python code. Which is great<br>
because it's totally general -- that's why we love pickle, you can<br>
pickle anything -- but that exact feature is what makes it insecure.<br>
If you want to make something secure, that means making some explicit<br>
decisions about what kinds of things can be put into your data format<br>
and which cannot, and write some explicit code to handle each of these<br>
things instead of just handing the file format direct access to your<br>
interpreter. But by the time you've done that you've done the hard<br>
part of implementing a new format anyway...<br></blockquote><div><br></div><div>Wouldn't it be easier to just tell unpickle which code it's allowed to run (by passing a list of modules and classes)?  Then your serializer can be reused by deepcopy and other Python routines that might tie into "reduce"?  I think that's easier than "implementing (yet another) a new format".</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class="HOEnZb"><font color="#888888"><br>
-n<br>
<br>
--<br>
Nathaniel J. Smith -- <a href="http://vorpus.org" rel="noreferrer" target="_blank">http://vorpus.org</a><br>
</font></span></blockquote></div><br></div></div>