5 ms·
Thanks - this kind of feedback is exactly why we're putting this out for review. Can you provide pointers or a bit more information as to how the timeable issu
by simonw 17y ago
Thanks - this kind of feedback is exactly why we're putting this out for review.
Can you provide pointers or a bit more information as to how the timeable issue works, and what the workaround is?
Is there a more technically correct term we should be using instead of 'salt'? And is that feature a total waste of time? Remember, we're building a framework for other developers to use - so saying "you shouldn't be using HMAC signatures in so many places that keying them individually is a problem" assumes that developers using Django (who may have no crypto / security knowledge at all) will understand that. Is this something we should cover in the documentation?
- tptacek 17y agoYou appear to have the same vulnerability as Google Keyczar had: http://rdist.root.org/2009/05/28/timing-attack-in-google-keyczar-library/ http://rdist.root.org/2009/05/28/timing-attack-in-google-key... Which leads to the question: why aren't you simply using Keyczar?
- simonw 17y agoWe try to keep Django's dependencies down to the Python standard library + a database adapter, so I'm pretty limited on which underlying crypto libraries I can use. How big a deal is that timing attack? Would it be appropriate to ignore it by default, but provide people who are concerned about it the option to swap out the sha1 signing for something using an external library that isn't affected by it. Or even just drop an optional "time.sleep(random.random() * 0.01)" line in to the code that generates the signatures?
- tptacek 17y agoIt's a big enough deal that if I'm right (I looked at your code for about 15 seconds) and you ship it, you will look ridiculous when someone blogs the exploit code.
- patio11 17y agoThomas is the security consultant, I sell bingo cards to 60 year old women, take with appropriate grains of salt: the timing attack is impractical against almost all Django installations, and is difficult to exploit Internet-wide in an automated fashion (like, e.g., you can do for Wordpress vulnerabilities). However, the impact is probably severe if your installation is vulnerable (i.e. if the bad guy can get sufficiently local access to your site over the network, and if you allow him sufficient rejected attempts). This can happen in plausible circumstances. For example, if you host on Slicehost and the bad guy is sufficiently motivated to pay $20 a month and buy himself a slice in your data center, congratulations, it is highly likely you are vulnerable to timing attacks in this manner. (This vulnerability is by no means unique to Slicehost, I'm just using this as a practical example of how a dedicated adversary can plausibly exploit a common deployment scenario.) If you're vulnerable, the bad guy can compromise signatures given a long enough time. I am not a Django guy but I am a Rails guy, and one common pattern we have is to store things in the session where the session is serialized into the cookie. For example, we might store the authenticated user_id there. (I do.) The signing is what keeps someone from swapping out user_id = 12387 (their freebie account) for user_id = 1 (my all-powerful admin account) and convincing the system that the user logged into their browser is me. If you can forge a signature, free admin for you. Given that this vulnerability has catastrophic consequences for vulnerable users and you probably encourage coding practices which make users vulnerable to it, I'd put it pretty high on my list of things to fix prior to release. But again, I am not the security guy.
- brown9-2 17y agoI think that the issue is compounded here by the fact that Django is a framework which will be used in hundreds or thousands (or more) of applications deployed all over the world. Any security issue with the framework itself instantly puts thousands of apps at risk. If you have a single app then you can discount this kind of attack, but when you are producing code that will be used in thousands of other apps, it would be irresponsible to do so.
- tptacek 17y ago
- simonw 17y agoForget the dumb time.sleep() idea, I just looked at the keyczar implementation of constant time string comparison. I'll roll that in to the library, thanks.
- Tuna-Fish 17y agoGood. By the way, the time.sleep wouldn't even have worked -- the big deal with timing things on the web is that unless you run some kind of autobanning script, they get unlimited attempts. I'm pretty sure that if I get a hundred-thousand-similar-attempt dataset I can calculate the mean time to such accuracy that the random sleep time doesn't hamper me at all. And I can collect that data over such a large time you might not even notice.
- simonw 17y agoYeah, I figured that after I read up on the timing attack and saw that it's based on statistics over many runs. Crypto is hard!
- illumen 17y agohello, I just tested the keyczar routine, and it can still be found. The sleep needs to be long enough, and random enough that it makes the other variance statistically insignificant. cheers,
- tptacek 17y agoWhat version of Keyczar did you test? Here's the current code: http://code.google.com/p/keyczar/source/browse/trunk/python/src/keyczar/keys.py http://code.google.com/p/keyczar/source/browse/trunk/python/... From the code: correctMac = self.Sign(msg) if len(sig_bytes) != len(correctMac): return False result = 0 for x, y in zip(correctMac, sig_bytes): result |= ord(x) ^ ord(y) return result == 0 This code performs the same ALU ops on every byte of the MAC, and does not perform any bytewise comparisons if the MACs aren't the same size. It's not timeable.
- 17y ago
- houseabsolute 17y ago> We try to keep Django's dependencies down to the Python standard library Any good reasons for this?
- simonw 17y agoPersonal opinion: It's probably one of the reasons we're the most popular Python web framework, especially amongst people with no prior Python experience. We may change that policy in the future (we've discussed it) but we're not going to change it just so the signing feature can get in to Django 1.2 - and I'd really like to get signing in to 1.2.
- houseabsolute 17y agoIt will be interesting to see if anyone has their identity stolen as an indirect consequence of this decision.
- deleted 17y ago[deleted]
- tptacek 17y agoNobody is going to have their identity stolen because of this feature, but it would be nice if they stopped implementing any more crypto. Arguing against signed cookies is tilting at windmills, but that doesn't mean marketing crypto features is a smart move.
- ubernostrum 17y agoAdding to what Simon said, dependencies in Python are an absolute mess, with no truly reliable mechanism other than saying "here's a list of what you'll need, go install it all manually". So every additional dependency is a major burden in terms of packaging, documentation, learning curve for newbies, etc. and we try to avoid inflicting that unless it's absolutely necessary. (though personally I think I'd prefer to outsource crypto to, you know, people who actually know how to do it)
- deleted 17y ago[deleted]
- simonw 17y agoI just had a more detailed look at Keyczar and it's pretty awesome. Unfortunately it depends on pycrypto which is a tough dependency for Django as a whole. We already have a mechanism for allowing you to "swap out" the hashing backend used for Django's get_signed_cookie and set_signed_cookie functions. It wouldn't be at all hard to write an optional keyczar backend for that. I think I'll do that. I'll need to extend the configurable backend aspect to cover other things within Django that use signing as well.
- illumen 17y agoI just tested the python fix there, and it was easy to find the difference with the python function given. The solution is to rate limit, and add random small sleeps. A tiny random sleep stops the variance from a string compare showing up. Rate limiting and blocking slow down an attacker from trying out lots of attempts anyway. If you have decent signal processing skills you should be able to show another keyczar exploit.
- tptacek 17y agoThat's a terrible fix. Adding noise degrades the signal without eliminating it. To defeat that countermeasure, you just take more measurements. The random sleeps, which are by nature random, get filtered out. The Keyczar Python fix --- if we're talking about Nate Lawson's code --- has no data-dependent timing. It invariably does the same ALU ops on every byte of the string, and fails if the strings aren't of the same length. That's the right solution to side channel vulnerabilities: eliminate the side channel.