On Thu, Sep 24, 2009 at 3:22 PM, Benjamin Slavin <benjamin.sla...@gmail.com> wrote: >> response.set_cookie('key', 'value', sign=True) >> - results in a Set-Cookie: key__Xsigned=value header > > Unfortunately, this approach won't work. > > A malicious client can just send "key" rather than "key__Xsigned" and > you'll never know that the cookie hasn't gone through validation. > This also means that you can't look for cookie values that match a > specific format (ex: body.signature) because a malicious client could > just drop the signature portion. > > As always, we can't trust the client. :-(
And you've just added another reason my followup email is invalid, though I sent that before reading your response. (Take that, future me!) > 3) COOKIES as an intelligent object -- We can overload .get so we're > doing something like request.COOKIES.get('foo', signed=True) -- I > think this has the best chance at an interface that keeps a consistent > feel. It's completely backward compatible, though it breaks the > traditional expectation of what you can do via the `get` method on a > dictionary. I was wondering about this option as well, after I mentioned adding a request.COOKIES.get_unsigned() method. I actually like this idea a lot, personally. As you mention, it's backward compatible, and I'm not sure it completely breaks the traditional expectation. After all, aren't subclasses expected to customize the behavior of their parents? It doesn't change any existing behavior, but rather just adds something extra. The one downside to using get() directly, as opposed to an altogether new method, is that get() doesn't raise a KeyError when a value doesn't exist. That means if anyone's wrapping request.COOKIES[key] in a try block and catching KeyError, changing to the new code is more than just a one-liner. I'm personally okay with this, but it's definitely worth noting. -Gul --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---