From: Simon Willison <si...@simonwillison.net>
Date: Thu, 24 Sep 2009 12:46:28 -0700 (PDT)
Local: Thurs, Sep 24 2009 3:46 pm
Subject: Re: Adding signing (and signed cookies) to Django core
On Sep 24, 8:22 pm, Benjamin Slavin <benjamin.sla...@gmail.com> wrote:
> Unfortunately, this approach won't work.
Good point - that rules that approach out.
> A malicious client can just send "key" rather than "key__Xsigned" and
> As always, we can't trust the client. :-(
> 1) request.unsign_cookie('foo') -- This breaks the parallelism with
If we were going to do that, it would make sense to NOT have set_cookie
> existing cookies. Sometimes we'll be doing request.COOKIES['foo'] and > sometimes we'll be doing request.unsign_cookie('foo'). (... sign=True) as the API for setting one. We could achieve parallelism with something like this: response.sign_cookie('key', 'value')
You can still read request.COOKIES directly, but you'll get the raw,
> 2) A decorator for views -- @unsign_cookies("foo", "bar") -- This
If a cookie is improperly signed I think you silently discard it, as
> doesn't allow any sort of fall-back (you can't customize what to do if > a given cookie is improperly signed) if it was never set. If we had logging this could always be logged as well... we could fire a signal if we really think people might want to further customise it. > 3) COOKIES as an intelligent object -- We can overload .get so we're
This isn't so bad, since we already have a precedent for this in
> 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. request.POST.get_list('foo'). request.COOKIES.get_signed(key) might be OK. At the moment I think my preference is for response.sign_cookie and
Cheers,
Simon
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||