Skip to content

Commit 6ff63c8

Browse files
authored
Display error if twofaSecret cannot be retrieved (#14372)
1 parent 2686e6b commit 6ff63c8

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ or_enter_secret = Or enter the secret: %s
625625
then_enter_passcode = And enter the passcode shown in the application:
626626
passcode_invalid = The passcode is incorrect. Try again.
627627
twofa_enrolled = Your account has been enrolled into two-factor authentication. Store your scratch token (%s) in a safe place as it is only shown once!
628+
twofa_failed_get_secret = Failed to get secret.
628629

629630
u2f_desc = Security keys are hardware devices containing cryptographic keys. They can be used for two-factor authentication. Security keys must support the <a rel="noreferrer" href="https://fidoalliance.org/">FIDO U2F</a> standard.
630631
u2f_require_twofa = Your account must be enrolled in two-factor authentication to use security keys.

routers/user/setting/security_twofa.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,14 @@ func EnrollTwoFactorPost(ctx *context.Context, form auth.TwoFactorAuthForm) {
189189
return
190190
}
191191

192-
secret := ctx.Session.Get("twofaSecret").(string)
192+
secretRaw := ctx.Session.Get("twofaSecret")
193+
if secretRaw == nil {
194+
ctx.Flash.Error(ctx.Tr("settings.twofa_failed_get_secret"))
195+
ctx.Redirect(setting.AppSubURL + "/user/settings/security/two_factor/enroll")
196+
return
197+
}
198+
199+
secret := secretRaw.(string)
193200
if !totp.Validate(form.Passcode, secret) {
194201
if !twofaGenerateSecretAndQr(ctx) {
195202
return

0 commit comments

Comments
 (0)