Backport Cookie Pickling Fix

This is a backport of 4d817b38875c900d70793acd528afc9e954bbcb7, which fixed incorrect pickling of cookies. Given that this bug can result in scrambled CSRF token cookies (discouraging their use), I think it's worth it.

The related ticket is [19262][1].

[1]: https://code.djangoproject.com/ticket/19262