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

Empty string is verified as correct due to Integer coercion #32

Closed
mkdynamic opened this issue Jul 13, 2014 · 7 comments
Closed

Empty string is verified as correct due to Integer coercion #32

mkdynamic opened this issue Jul 13, 2014 · 7 comments

Comments

@mkdynamic
Copy link
Contributor

Run this to illustrate what happens:

require 'rotp'

loop do
  totp = ROTP::TOTP.new(ROTP::Base32.random_base32, digits: 4)
  raise totp.now.inspect if totp.verify("")
end

I cannot think of why this would pose any security risk, but it was surprising initially. Although now I understand why it behaves like this after scoping the source, it still seems odd.

Thoughts?

@mdp
Copy link
Owner

mdp commented Jul 13, 2014

So this comes down to the fact that ROTP allows for integers to be submitted and verified.

In this loop, with a 4 digit OTP, there's a 1:1000 chance that the OTP will be "0000", at which point, "".to_i yields 0 and is compared to the OTP.

This is not ideal. Although I don't think it's a serious security risk for most users, it does increase the number of "right" OTP's for a user. For example, "052189", also verifies with "52189", so now you have two "correct" answers. Realistically, it should default to requiring a padded string to verify, and if developers want to verify numbers, they'll have to do that themselves. I'd rather default to a more secure method.

This will be out in 1.7.0 today.

@mdp mdp closed this as completed in 7c294b5 Jul 13, 2014
@mdp
Copy link
Owner

mdp commented Jul 13, 2014

Thanks Mark, this is out in 1.7.0

@mkdynamic
Copy link
Contributor Author

Cool, thanks @mdp

@mkdynamic mkdynamic changed the title Empty string is verified as correct due to interger coercion Empty string is verified as correct due to Integer coercion Jul 14, 2014
@rkh
Copy link

rkh commented Jul 22, 2014

Breaking the public API in a minor release. I'd like to voice that I'm very displeased with this. This change could have been introduced without breaking the API.

@mdp
Copy link
Owner

mdp commented Jul 22, 2014

Totally valid. I even looked at is as breaking API change in the git commit log and still only bumped it a minor level.

I've yanked 1.7.0 - The latest is in 2.0.0

I'm hoping this was quick enough to avoid any other people having issues. If you've already made the changes, just bump the version to 2.0.0 and you'll be good to go. Otherwise lock in at 1.6.1

Sorry for trouble this caused.

Edit: just bumped to 2.0.0 and yanked 1.7.0

@mdp
Copy link
Owner

mdp commented Jul 22, 2014

Update to my comment above. I'm just yanking the 1.7.x branch entirely. Lock to 1.6.x for the old API. Bump to 2.0.0 for the latest.

@rkh
Copy link

rkh commented Jul 22, 2014

Thanks a lot. <3

bsedat referenced this issue in devise-two-factor/devise-two-factor Jun 5, 2015
lisbethmarianne added a commit to travis-ci/travis-sso that referenced this issue Oct 28, 2016
Error message for using rotp-3.3.0: 

> ArgumentError (ROTP only verifies strings - See: mdp/rotp#32)

The rotp gem had an api change, it requires the argument passed to `verify` to be a string. To use the newer version of rotp, we can no longer cast the otp token to int.
danishsatkut added a commit to danishsatkut/google-authenticator that referenced this issue Dec 15, 2017
- Fixed broken tests due to rotp gem upgrade. See:
  mdp/rotp#32
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

3 participants