Skip to content
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

Suggestion: Don't use == comparison for authentication in sample code #133

Closed
dideler opened this issue Feb 4, 2015 · 3 comments
Closed

Comments

@dideler
Copy link
Contributor

dideler commented Feb 4, 2015

In the User Manual, the sample code for verifying the Mailgun authentication signature uses ==.

E.g. e306a37#diff-229131ed0af7cf80ed3a9470ec7beb4cR701

But == comparisons are vulnerable to timing attacks.
Is it worth mentioning to use a constant time comparison?

In Ruby, there's a secure_compare method provided by Rack and Rails.

# Rack
Rack::Utils.secure_compare(a, b)

# Rails
ActiveSupport::SecurityUtils.secure_compare(a, b)

In Python, there's a compare_digest function in the standard library.

import hmac
hmac.compare_digest(a, b)

Both languages also have 3rd party libraries if the reader doesn't want to use any of the above methods.

@pirogoeth
Copy link
Contributor

Hi, I'm working on a collection of these in #217 :)

@cogr4q
Copy link

cogr4q commented Feb 25, 2021

Do we have anything in Java to compare the digest?

@rob-spoor
Copy link

@cogr4q : MessageDigest.isEqual

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants