Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> How do I effortlessly restore objects including their methods from JSON?

The recommendation from the title is usually made instead of something like "deserializing executable data is harmful". That is exactly the one question where the answer is "don't".

It's not exactly the unpickling process that is the problem. It's how you established that the data isn't malicious. It is very hard to use pickle without creating some local privilege escalation possibilities. And at the end of the process, you usually don't get any capability that replicating the code on both sides of the communication channel wouldn't give you.

(The problem isn't specific to Python either. There was a time when that kind of functionality was very hyped on both the industry and academia. For example, Java also got something similar that they had to retract. The famous Gnu-Hurd OS (the one that would never finish) was supposed to do that on the system level.)



  Do you, Programmer,
  take this Object to be part of the persistent state of your application,
  to have and to hold,
  through maintenance and iterations,
  for past and future versions,
  as long as the application shall live?
Arturo Bejar, as quoted[1] in Mark Miller’s “Safe serialization under mutual suspicion”, which describes what it takes to make reasonable and compatible serialization restoring “all you can do is to send a message” objects.

(The Smalltalk school actually spent quite a bit of time on the upgrade problem, see e.g. Fuel[2] and its references, but it was after the industry took the object orientation shiny and ran away with it, so that work seems to be little-known outside it.)

[1] http://www.erights.org/data/serial/jhu-paper/upgrade.html

[2] http://wiki.squeak.org/squeak/6221


The Mozart/Oz people came up with pickle, I think.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: