UserSessionController::validate_code does not correctly handle validation codes with leading zeros #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Consider the user enters the validation code "012345". The list of
valid_codes
inUserSessionController::validate_code
will containROTP::TOTP.new(two_factor_secret).now
, which is the integer12345
. When you call.to_s
on that integer, you'll get "12345"."012345" != "12345"
, so even though the code was correct, validation fails. The solution outlined in my pull request calls.to_i
on the validation_code that the user passes in and no longer calls.to_s
on the validation codes computed by ROTP.