-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add secure equals method to prevent timing attacks #56
Conversation
I had never heard of a timing attack before, that's pretty interesting. Do you think it would be possible to perform a timing attack again api_auth considering the method used to generate the canonical string combined with the fact that the data here is being transmitted over the internet which introduces a lot of variability in time? |
@kjg watch the lecture in the link. He addresses the Internet latency/variability thing. Short answer: yes it can still be done over the net. |
My understanding is that Benchmark isn't great for testing timing attacks, as it does a fair amount of rounding. I wanted to put the numbers in here anyways in hopes that some solution is implemented to limit risks associated with these types of attacks. I tested master, @leishman's pull request, and Fast Secure Compare - (see [below](#Fast secure compare)) using the same two randomly generated secrets over 50,000 iterations of Here's the script I used for testing: https://gist.github.com/dacamp/8d970d7065931045d343
Fast secure compareUrl: https://github.com/daxtens/fast_secure_compare Method Hack:
|
I'm not seeing how this causes an exploit. Using the timing attack you can find calculated_hmac using a time of calculation, but that is unencrypted in the request headers anyway. In other words, I'm not seeing how using the attack can cause someone to find the secret_key (or edit the message, or some other vulnerability). For example, suppose you want to find the secret key. You start with However, iterating through the next character doesn't help you because changing the next character causes a significant change in the calculated hmac_signature. More formally |
Howdy! I'm interested in getting this resolved, and I'd be happy to take on resolving the conflicts. There are a couple of other related issues (happy to say if you're comfortable with this channel) in HEAD I'm interested in helping to resolve that collectively make attack easier |
@will0 I think there is a PR that is already up. Also, I realized secure comp is needed to prevent forging a request |
@johnmcconnell Just saw your comment from last year. The attack is not about finding the key, it's about brute-forcing the HMAC itself. If the HMAC is unencrypted in a request header, then it's vulnerable to a MITM. |
@johnmcconnell do you mean this PR that is up? |
@johnmcconnell thank you for pointing that out 👍 |
Fixed by #133 Thanks! |
@mgomes @kjg
I updated the
signatures_match?
method to prevent timing attacks. The equality operator should not be used to compare two strings for authentication in Ruby (I believe). For example:'abc' == 'abc'
will take longer to evaluate than'def' == 'abc'
because the ruby interpreter will return false after analyzing the first bytes of each string in the second example, but will iterate through each byte of the strings in the first example. This information can be used by a malicious actor in what is known as a timing attack.There are two solutions I know of to protect against this timing attack:
I learned about this attack from a Stanford cryptography professor in this lecture and he recommended the solution I propose here. His example is for Python but I assume that it applies to Ruby as well.
All tests pass.