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

Timing attack on basic password auth system #1258

Closed
carmi opened this issue Jan 26, 2016 · 3 comments
Closed

Timing attack on basic password auth system #1258

carmi opened this issue Jan 26, 2016 · 3 comments

Comments

@carmi
Copy link

carmi commented Jan 26, 2016

I'm just seeing in the README about basic auth https://github.com/ruby-grape/grape#authentication

http_basic do |username, password|
  # verify user's password here
  { 'test' => 'password1' }[username] == password
end

This sure looks like it's prone to a timing attack on the password like CVE-2015-7576 https://groups.google.com/forum/#!msg/rubyonrails-security/ANv0HDHEC3k/mt7wNGxbFQAJ and should ideally not be a recommended solution for password auth.

@carmi
Copy link
Author

carmi commented Jan 27, 2016

I think the proper way to do this to avoid the timing attack is (if you have ActiveSupport available)

    http_basic do |username, password|
      ActiveSupport::SecurityUtils.variable_size_secure_compare(GRAPE_API_USERNAME, username) &
        ActiveSupport::SecurityUtils.variable_size_secure_compare(GRAPE_API_PASSWORD, password)
    end

@dblock
Copy link
Member

dblock commented Jan 27, 2016

I got to admit that's an impressively obvious CVE. I suggest simply removing the specific example from the documentation and leaving the comment to verify the user's password. It's probably not Grape's responsibility to make sure you implement BASIC auth with this CVE in mind, otherwise we also would have to care about things like what headers you send to the client for, say, CSP.

@dblock
Copy link
Member

dblock commented Apr 11, 2020

Closed via #2037

@dblock dblock closed this as completed Apr 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants