Re: Adding signing (and signed cookies) to Django core

2009-10-24 Thread Johannes Dollinger
Am 25.09.2009 um 22:04 schrieb Simon Willison: > > On Sep 25, 4:44 pm, Johannes Dollinger > wrote: >> Regarding parity, let me advertise a Signer object again: >> >> signer = signed.Signer( >> key=settings.SECRET_KEY, >> expire_after=3600 >> ) >>

Re: Adding signing (and signed cookies) to Django core

2009-10-20 Thread Dennis
> Signed cookies are useful > for all sorts of things - most importantly, they can be used in place > of sessions in many places, which improves performance (and overall > scalability) by removing the need to access a persistent session > backend on every hit. Set the user's username in a signed c

Re: Adding signing (and signed cookies) to Django core

2009-10-06 Thread Matt Brubeck
On Oct 5, 1:44 pm, Simon Willison wrote: > Other than dates being a bit more annoying to pass around, I really > don't think that telling people they can only dumps/loads JSON- > encodable data would be a huge burden. You could use YAML instead if you want date support... although JSON does seem

Re: Adding signing (and signed cookies) to Django core

2009-10-05 Thread Simon Willison
On Oct 5, 6:33 pm, Matt Brubeck wrote: > On Sep 24, 10:18 am, Simon Willison wrote: > > This offers two APIs: sign/unsign and dumps/loads. sign and unsign > > generate and append signatures to bytestrings and confirm that they > > have not been tampered with. dumps and loads can be used to creat

Re: Adding signing (and signed cookies) to Django core

2009-10-05 Thread Matt Brubeck
On Sep 24, 10:18 am, Simon Willison wrote: > This offers two APIs: sign/unsign and dumps/loads. sign and unsign > generate and append signatures to bytestrings and confirm that they > have not been tampered with. dumps and loads can be used to create > signed pickles of arbitrary Python objects.

Re: Adding signing (and signed cookies) to Django core

2009-09-27 Thread Simon Willison
I've started a project on GitHub to develop the signing implementation: http://github.com/simonw/django-signed The TODO section in the readme shows the next things I'll be working on. --~--~-~--~~~---~--~~ You received this message because you are subscribed to th

Re: Adding signing (and signed cookies) to Django core

2009-09-25 Thread Simon Willison
On Sep 25, 4:44 pm, Johannes Dollinger wrote: > Regarding parity, let me advertise a Signer object again: > >         signer = signed.Signer( >                 key=settings.SECRET_KEY, >                 expire_after=3600 >         ) > >         s = signer.sign(v) >         v = signer.unsign(s) >

Re: Adding signing (and signed cookies) to Django core

2009-09-25 Thread Tobias McNulty
On Thu, Sep 24, 2009 at 5:33 PM, Chris Beaven wrote: > > Personally, I don't see much point in specifically reporting on > incorrectly signed cookies - imo they should just be treated as if > they never existed. If someone really cared, they can look in > request.COOKIES to see if the cookie was i

Re: Adding signing (and signed cookies) to Django core

2009-09-25 Thread Marty Alchin
On Fri, Sep 25, 2009 at 10:42 AM, Simon Willison wrote: > On Sep 25, 3:39 pm, Simon Willison wrote: >> While that makes sense for caching, I couldn't say if it makes sense >> for signatures or not - when we sign something, will we always know >> the point at which we want that signature to expir

Re: Adding signing (and signed cookies) to Django core

2009-09-25 Thread Johannes Dollinger
> Would expire_after on the unsign just automatically imply > timestamp=True? There's been a lot of concern raised about parity in > the API, and it reads a little weird with the two different arguments. > I'm not sure it's a problem, but it's just a little funny. Regarding parity, let me advert

Re: Adding signing (and signed cookies) to Django core

2009-09-25 Thread Simon Willison
On Sep 25, 3:39 pm, Simon Willison wrote: > While that makes sense for caching, I couldn't say if it makes sense > for signatures or not - when we sign something, will we always know > the point at which we want that signature to expire? I don't know. Here's a good argument for signing things wi

Re: Adding signing (and signed cookies) to Django core

2009-09-25 Thread Simon Willison
On Sep 25, 3:10 pm, Marty Alchin wrote: > The timestamp would then be the actual expiration > time, rather than the time it was signed, so the API can look like > this instead (with a key added per prior discussion). > > >>> s = signed.sign('key', 'value') > >>> v = signed.unsign('key', s) > >>>

Re: Adding signing (and signed cookies) to Django core

2009-09-25 Thread Marty Alchin
On Fri, Sep 25, 2009 at 9:26 AM, Simon Willison wrote: > The API would look something like this: > s = signed.sign('value', timestamp=True) v = signed.unsign(s, expire_after=24 * 60 * 60) > > A SignatureExpired exception would be raised if the signature was > older than the expire_after

Re: Adding signing (and signed cookies) to Django core

2009-09-25 Thread Simon Willison
On Sep 25, 1:57 pm, Marty Alchin wrote: > I think this is good for everywhere the raw signing API is accessed, > perhaps to the point where that API can't even be used without a key > (a namespace, really - honking great idea!). Helpers on top of that > API could do without asking for that separa

Re: Adding signing (and signed cookies) to Django core

2009-09-25 Thread Simon Willison
On Sep 25, 1:57 pm, Marty Alchin wrote: > I wish there was > a way to sign the expiration as well, so people couldn't artificially > extend the life of the cookie, but since that doesn't come back in the > request, there'd be no way to validate it. We can do that by baking the timestamp the cook

Re: Adding signing (and signed cookies) to Django core

2009-09-25 Thread Marty Alchin
On Fri, Sep 25, 2009 at 7:02 AM, Luke Plant wrote: > Suppose one part of an app signs an e-mail address for the purpose of > an account confirmation link sent in an e-mail.  The user won't be > able to forge the link unless they know HMAC(SECRET_KEY, email). > > However, suppose another part of t

Re: Adding signing (and signed cookies) to Django core

2009-09-25 Thread Luke Plant
On Friday 25 September 2009 12:27:53 Simon Willison wrote: > Do you have any further information on the WordPress problems? No, I can't find it. It might not have been WordPress. All I remember is that it was along the lines of what I outlined in my previous e- mail -- one part of the applicat

Re: Adding signing (and signed cookies) to Django core

2009-09-25 Thread Andrew Gwozdziewycz
On 9/24/09 9:56 PM, Ian Lewis wrote: > On Fri, Sep 25, 2009 at 6:33 AM, Chris Beaven wrote: > >> +1 on the concept of a signing module. >> >> On Sep 25, 7:48 am, Marty Alchin wrote: >> >> >>> The one downside to using get() directly, as opposed to an altogether >>> new method, is that

Re: Adding signing (and signed cookies) to Django core

2009-09-25 Thread Simon Willison
On Sep 25, 12:02 pm, Luke Plant wrote: > In other web apps (I think Wordpress?), there have been problems > associated with use of secret keys when the same key is used for > different purposes throughout the application. > ... >  - we add unique prefixes to the SECRET_KEY for every different >  

Re: Adding signing (and signed cookies) to Django core

2009-09-25 Thread Dan Watson
On Sep 24, 3:46 pm, Simon Willison wrote: > > 1) request.unsign_cookie('foo') -- This breaks the parallelism with > > existing cookies.  Sometimes we'll be doing request.COOKIES['foo'] and > > sometimes we'll be doing request.unsign_cookie('foo'). > > If we were going to do that, it would make s

Re: Adding signing (and signed cookies) to Django core

2009-09-25 Thread Luke Plant
On Thursday 24 September 2009 18:18:56 Simon Willison wrote: > SECRET_KEY considerations > = Can I add some other things I've been worrying about while we're on the topic? In other web apps (I think Wordpress?), there have been problems associated with use of secret ke

Re: Adding signing (and signed cookies) to Django core

2009-09-25 Thread Simon Willison
On Sep 25, 4:48 am, Russell Keith-Magee wrote: > By way of greasing the wheels towards trunk: if the outcome of this > mailing list thread was a wiki page that digested all the ideas, > concerns and issues into a single page, it will make the final > approval process much easier. Great idea: htt

Re: Adding signing (and signed cookies) to Django core

2009-09-24 Thread Eric Florenzano
A big +1 on signed cookies, and I like the direction the discussion is going. Also, I hope this doesn't derail this discussion, but I hope after signed cookies are added, auth can be made to optionally use signed cookies instead of sessions. Thanks, Eric Florenzano --~--~-~--~~--

Re: Adding signing (and signed cookies) to Django core

2009-09-24 Thread Russell Keith-Magee
On Fri, Sep 25, 2009 at 1:18 AM, Simon Willison wrote: > > As mentioned in the thread about cookie-based notifications, at the > DjangoCon Sprints I raised the subject of adding signing (and signed > cookies) to Django core. > > I've found myself using signing more an

Re: Adding signing (and signed cookies) to Django core

2009-09-24 Thread Chris Beaven
On Sep 25, 1:56 pm, Ian Lewis wrote: > [...] unless accessing > COOKIES gives you raw values of ALL cookies and SIGNED_COOKIES > attempts to unsign ALL cookies. That seems really clunky. Yes, all cookies would stay in COOKIES. SIGNED_COOKIES would be a lazy dict-like object, not a plain dictiona

Re: Adding signing (and signed cookies) to Django core

2009-09-24 Thread Ian Lewis
On Fri, Sep 25, 2009 at 4:46 AM, Simon Willison wrote: > This isn't so bad, since we already have a precedent for this in > request.POST.get_list('foo'). request.COOKIES.get_signed(key) might be > OK. request.COOKIES.get_signed(key) makes the most sense to me since it's clear you are dealing wit

Re: Adding signing (and signed cookies) to Django core

2009-09-24 Thread Ian Lewis
On Fri, Sep 25, 2009 at 6:33 AM, Chris Beaven wrote: > > +1 on the concept of a signing module. > > On Sep 25, 7:48 am, Marty Alchin wrote: > >> 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 exi

Re: Adding signing (and signed cookies) to Django core

2009-09-24 Thread Chris Beaven
+1 on the concept of a signing module. On Sep 25, 7:48 am, Marty Alchin wrote: > 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 t

Re: Adding signing (and signed cookies) to Django core

2009-09-24 Thread Johannes Dollinger
How about Signer class? signer = Signer(key=...) assert signer.unsign(signer.sign(value)) == value This way you wouldn't have to pass around key, extra_key, and potential further arguments but a single Signer instance. Plus, you could easyly overwrite hashing, concatenation,

Re: Adding signing (and signed cookies) to Django core

2009-09-24 Thread Marty Alchin
On Thu, Sep 24, 2009 at 3:22 PM, Benjamin Slavin 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 k

Re: Adding signing (and signed cookies) to Django core

2009-09-24 Thread Simon Willison
On Sep 24, 8:22 pm, Benjamin Slavin wrote: > 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

Re: Adding signing (and signed cookies) to Django core

2009-09-24 Thread Marty Alchin
> Also, does the name of a cookie factor into the cookie length limits? > My reading of RFC 2109 says yes, but it'd be worth verifying, since it > would cut down on the usable value space. With your compressed base64 > stuff, that's not as big of a problem, but still something to look > into. Als

Re: Adding signing (and signed cookies) to Django core

2009-09-24 Thread Benjamin Slavin
The lack of parallelism in terms of the interface is my biggest hangup here. I do think that this should find it's way into trunk, as signed cookies are important in the use cases you mention and are really easy to get wrong... and getting it wrong can be dangerous. I'm not going to get into the

Re: Adding signing (and signed cookies) to Django core

2009-09-24 Thread Marty Alchin
On Thu, Sep 24, 2009 at 2:54 PM, Simon Willison wrote: > Hmm... I hadn't considered that. I was thinking that the unsigning > could be transparent, so by the time you access request.COOKIES['key'] > the value had already been unsigned (and if the signature failed the > cookie key just wouldn't be

Re: Adding signing (and signed cookies) to Django core

2009-09-24 Thread Simon Willison
On Sep 24, 7:37 pm, Marty Alchin wrote: > Another option would be to have request.COOKIES be a custom > dictionary, with an extra .get_unsigned(key) method that would work > like .get(), but validates the signature along the way. That behavior > can't be added straight to __getitem__() though, be

Re: Adding signing (and signed cookies) to Django core

2009-09-24 Thread Marty Alchin
I'm obviously going to weigh in here, having authored the signed cookies app you mentioned below, but be aware I'm not a cryptographer, nor do I have any personal use for signed cookies at all. I can appreciate their value, but I'm not even using my own app in anything, so if there are problems wi

Re: Adding signing (and signed cookies) to Django core

2009-09-24 Thread Tobias McNulty
18 PM, Simon Willison wrote: > > As mentioned in the thread about cookie-based notifications, at the > DjangoCon Sprints I raised the subject of adding signing (and signed > cookies) to Django core. > > I've found myself using signing more and more over time, and I think >

Adding signing (and signed cookies) to Django core

2009-09-24 Thread Simon Willison
As mentioned in the thread about cookie-based notifications, at the DjangoCon Sprints I raised the subject of adding signing (and signed cookies) to Django core. I've found myself using signing more and more over time, and I think it's a concept which is common enough to deserve in