4 ms·
One of my big concerns is user / session security. I have tried to follow and reason through discussions on stackoverflow and much of tpatchek's notes. I woul
by lifeisstillgood 14y ago
One of my big concerns is user / session security.
I have tried to follow and reason through discussions on stackoverflow and much of tpatchek's notes. I would be interested in how "high level" the security chapter is from anyone who has shelled out already.
For example I assume I will
1. only use persona or openid (avoids storing passwords in my servers thus making a lot of things much much easier)
2. sessions - store absolutley nothing in a session cookie other than a nonce session id, and lookup everrything I need from cache on servers form that sessionId
3. That seems to be it really
I just do not know where to go to have this discussion sensibly - any hints?
- wahnfrieden 14y agoYour 2nd point has significant performance implications, so I wouldn't take that for granted. Your 1st point is pretty controversial and has significant UX implications. Using OpenID instead of just the built-in Django auth or bcrypt is hardly "much much easier" either, it's far more complex to integrate.
- jmathai 14y agoI don't think the 2nd point has significant performance implications. If you're not serving up static pages then there's always network calls to be made on the backend. Storing a nonce on the client and looking everything up on the backend is an easy solution which means you don't have to worry about what data you're storing and if that'll be available in the browser. I think it's cheaper to optimize on the backend for a simpler (and safer) solution.
- lifeisstillgood 14y agoThank you - my thoughts too I cannot trust anything returned from a client so it seems best to Only return one thing from the client As for a carefully vetted security pro - that's great but I am looking for basic generic best practises (we know that has evolved from md5 hashes to bcrypt but what else is there?) It seems either a hole in my education or a hole in general common knowledge
- ivix 14y agoI think the point of a framework like django is that the defaults are best practices. It's good to understand why it does the things it does, but without a certain amount of trust in the framework, you can lose a lot of it's advantages.
- pydanny 14y agoDisclaimer: I'm one of the authors. The book covers 7 pages that gets you started down the road of understanding security. We provide you the stuff you have to know, and point you towards better resources. Keep in mind we aren't professional security experts. If your site needs to be that secure, the best thing you can do is to hire the services of a carefully vetted security expert.
- S_A_P 14y agoI think a great title for the security chapter should be Django Unchained. I look forward to reading this- Thanks.
- pydanny 14y agoROFL
- walls 14y agoIs this book going to be finished any time soon, or will it sit in the 'Alpha' state until you guys need more money? (cough John Resig cough)
- jonknee 14y agoI'm not sure what this has to do with the focus of the book, Django has session support so I doubt a book about Django would fully cover re-writing one of its components. Django used to only be able to store nothing in the session cookie other than the ID so that part can definitely happen (new in Django 1.4 are Cookie Based Sessions that used signed cookies to store data in cookies, but it's something you have to turn on). This is all fully documented, if you're curious you should read it. https://docs.djangoproject.com/en/1.5/topics/http/sessions/ https://docs.djangoproject.com/en/1.5/topics/http/sessions/ As for tying into OpenId or other similar systems, it's a piece of cake. There are numerous Django apps out there to accomplish it. I have used django-social-auth for a project and had no problems getting things running: https://github.com/omab/django-social-auth https://github.com/omab/django-social-auth
- lifeisstillgood 14y agoA brief read of the sessions docs throws up three concerns 1. Stuffing a lot into a session cookie (the term can easily exceed he 4096 bytes limit suggests that this is not designed just to store session ids) 2. There is implication of one site secret key - a flaw in Flask which it's dangerous was supposed to fix - but even so there is the implication the MAC check guarantees No one has played with the cookie. This is flat eke bread and butter breaking those 3. It still is making the base assumption that the developer can willingly stick whatever he likes in a python duct and have that magically comeback from the client untouched - of that seems to be so. Just I prefer having caching problems on my server than never knowing if the information from the cookie can be trusted
- jonknee 14y agoYes, if you change the defaults and don't read the docs it is possible to get in trouble.
- lifeisstillgood 14y agoThat seems disingenuous - a read of the docs indicates to me that the default is to store a lot of app specific info on an encrypted cookie - what is stored on that cookie? Admin rights? Total credit in dollars? Discount codes? That's app specific but if the implication is its trustable then a lot of attack vectors just opened up. who chooses the encryption? Is a new key generated per user / session? If so how is that stored and looked up? Any lookup drops the secure vs speedy trade off and so you need not store anything in the session cookie Yes it is possible to make a app insecure - we do it all the time. My question is how to generically and sensibly reduce the attack surface - you know, best practises. I just do not see the trade off of "encrypt everything onto a cookie and use that instead of cache lookups" as one I am willing to take - but I would like to know if I am in a minority, if there is evidence backing either side etc Edit: this appears to have been typed out of my bottom - the parents has pointed out the clearly marked defaults for django that meet seemingly most or all of my concerns above - but I cannot reply just yet (not sure why it might be a enforced Cooling off period) so this is the best way to say mea culpa
- izak30 14y ago1. Using recent django (1.4+) will get you _very good_ password storing security. Use HTTPS and you're "as good as anybody else". no persona/openid needed 2. Django has signed cookie sessions (optional to be used) and a solid signing library. This ensures that the data that is returned is the same as the data that was stored. This doesn't mean that a cookie can't be hijacked, so you should take care to have acceptable timeouts and such. These two things are the building blocks of secure sessions and passwords that work well in distributed systems.
- shabble 14y agoIt does use the 'do fancy things with HMAC signed tokens' to handle password reset though, which (as a general scheme) has been criticised vs the 'store random dumb token, details in the DB' method, for being difficult to do right and open to subtle flaws. Obviously I'm not aware of any Django-specific issues with it (or I'd have reported them already), but it's a design decision I've wondered about.
- izak30 14y agoAny details on the criticism? All curiosity for me at this point.
- shabble 14y agoThere was some discussion in a thread a few days back[1] in which I asked a similar question. It boils down to "possible, but very easy to screw up, and for what is probably relatively small benefit." The only benefits I can think of for the info-in-token approach are: * Less database hits to validate a token. Given that password resets are probably only a small part of your site load, I'm dubious as to the utility of this optimisation. * No server-stored tokens to secure - If an attacker manages to dump or partially break your database (SQLi, logic bug, whatever), they could extract the reset tokens and use them to gain access. Obviously, a full db exploit would make this unnecessary, and a proper reset implementation (that expires the tokens after use, sends confirm emails on use, etc) means unauthorised use would hopefully be detected. In the info-hash-token, the only place it's ever actually stored is in the user's mail-box (and every email server involved in the process along the way, potentially), which might reduce the risk of disclosure, especially bulk (server dump) disclosure. Any other advantages I might have missed? It's possible to do things like token expiry, invalidate on use, invalidate outstanding tokens using hashed tokens, but all of those things are fraught with danger. [1] https://news.ycombinator.com/item?id=5033266 https://news.ycombinator.com/item?id=5033266
- alinajaf 14y agoIf you're interested in security and have been following tptaceks notes, then no doubt you will have seen his recommendation for reading The Web Application Hackers Handbook. I'm just a rank-and-file web developer, but I would also strongly recommend reading this book, regardless of what language or framework choice you've made.
- lifeisstillgood 14y agoThank you - it seems to ring a bell so I will try my google-fu
- haukur 14y agoI'm going to use OpenID for an application soon, but I don't know what I should read or where to start. Do you have any recommendations? Thanks ;)