Merge branch 'sh-fix-otp-backup-invalidation-10-5' into 'security-10-5'

Ensure that OTP backup codes are always invalidated - 10.5 port

See merge request gitlab/gitlabhq!2324
This commit is contained in:
Douwe Maan 2018-02-09 15:02:11 +00:00 committed by James Lopez
parent 5d12970985
commit 6deed66eda
No known key found for this signature in database
GPG Key ID: 756BF8E9D7C0CF39
3 changed files with 18 additions and 0 deletions

View File

@ -56,6 +56,7 @@ module AuthenticatesWithTwoFactor
session.delete(:otp_user_id)
remember_me(user) if user_params[:remember_me] == '1'
user.save!
sign_in(user)
else
user.increment_failed_attempts!

View File

@ -0,0 +1,5 @@
---
title: Ensure that OTP backup codes are always invalidated
merge_request:
author:
type: security

View File

@ -145,6 +145,18 @@ feature 'Login' do
expect { enter_code(codes.sample) }
.to change { user.reload.otp_backup_codes.size }.by(-1)
end
it 'invalidates backup codes twice in a row' do
random_code = codes.delete(codes.sample)
expect { enter_code(random_code) }
.to change { user.reload.otp_backup_codes.size }.by(-1)
gitlab_sign_out
gitlab_sign_in(user)
expect { enter_code(codes.sample) }
.to change { user.reload.otp_backup_codes.size }.by(-1)
end
end
context 'with invalid code' do