From: Marty Alchin <gulop...@gmail.com>
Date: Thu, 24 Sep 2009 14:37:43 -0400
Local: Thurs, Sep 24 2009 2:37 pm
Subject: Re: Adding signing (and signed cookies) to Django core
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 with it, I haven't experienced them first-hand. I won't comment on everything, because I certainly trust your thoughts on the matter. (Your comment on the Django book is what prompted me to write the app in the first place!) I do have a couple thoughts, though. So, anything I don't comment on, I agree with. On Thu, Sep 24, 2009 at 1:18 PM, Simon Willison <si...@simonwillison.net> wrote: I have no idea how hmac differs from straight sha1, but this was > It's also something that's hard to do correctly. At the sprints Armin > pointed out that I should be using hmac, not straight sha1, for > generating signatures (something Django itself gets wrong in the few > places that implement signing already). Having a cryptographer- > approved implementation will save a lot of people from making the same > mistakes. raised in a django-signedcookies issue as well, and i've since integrated it. I'm with you on this; if somebody who knows better recommends something, I'm inclined to listen. > I think signed cookies should either be a separate API from I admit, I hadn't considered third-party cookies when I put it > response.set_cookie or should be provided as an additional argument to > that method. I'm not a fan of signing using middleware (as seen in > http://code.google.com/p/django-signedcookies/ ) since that approach > signs everything - some cookies, such as those used by Google > Analytics, need to remain unsigned. together as a decorator. Client-side cookie access is likely problematic as well, but that'll always be questionable anyway. You can't validate a cookie in the client without divulging your secret key and you can't just ignore the signature, because that defeats the whole purpose. My app also provides a decorator, which might help in some rare situations, but most of the time things like analytics cookies will be in a base template and will always be included in whatever view happens to have the decorator. I'm very surprised that in all this time, nobody submitted a bug about the analytics problem. > So the API could either be: I prefer the latter as well, for an added reason. I'd personally like > response.set_signed_cookie(key, value) > Or... > response.set_cookie(key, value, signed=True) > (I prefer the latter option) to invest some time in seeing if there are any other interesting pitfalls in set_cookie() based on it deferring to Python's SimpleCookie implementation. When writing Pro Django, I realized that SimpleCookie expects everything to be strings, so #6657 came up with secure=False resulting in a secure cookie after all. I don't know if there are other such issues, but it might be worth looking at in detail if we already have to add in signed cookie support. And before anyone asks, no I don't think tying the signing behavior But I do have one other concern with either of these APIs that is at response.set_cookie(key, value, signed=True) Mainly, unsigning a cookie requires importing and directly using the Another option would be to have request.COOKIES be a custom These are the types of issues that led me to just implement it as a >>>> signed.unsign('hello.9asVJn9dfv6qLJ_BYObzF7mmH8c') I'm not a big fan of this, personally. Yes, it does make things > 'hello' >>>> signed.unsign('hello.badsignature') > Traceback (most recent call last): > ... > BadSignature: Signature failed: badsignature > BadSignature is a subclass of ValueError, meaning lazy developers > try: slightly easier, by not requiring a separate import, but we already have django.core.exceptions.SuspiciousOperation exists for a reason, and a missing or invalid signature would certainly qualify, in my eyes. Yeah, I suppose we could perhaps make that a subclass of ValueError or TypeError, but I would worry about people wrapping it up into something else that might cause problems. try: I don't know how likely this is to happen, since the only examples I Of course, you could just as easily argue that people shouldn't be > Potential uses I think this is a big win for including signing as a separate piece > ============== > Lots of stuff: > - Signed cookies (obviously) from signed cookies, because you have a much bigger list of use cases, which can make it easier for people to understand the value. One of the most common questions I got on my app was, "why would I want to sign my cookies?" I think expanding the available uses signing will help answer that question. > So... what do people think? Is this a feature suitable for Django All in all, I understand and appreciate the benefits of signing > (obviously I think so)? Is this as simple as getting a cryptographer's > input and dropping signed.py in to django.utils or are there other > design factors we should consider? things, and I'd like that behavior to be made available reliably and easily, and it looks like that would require them being in core. I'm a little worried about ease of use, though, because it seems like most of the ways to make things easy can also make things either more confusing or less flexible. I'm a little scattered on the moment, but I think it's definitely worth refining into something that can go into core. -Gul 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.
| ||||||||||||||