Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions backend/internal/2fa.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,14 @@ const internal2fa = {
throw new errs.ValidationError("2FA is not enabled");
}

const result = await verify({
token: code,
secret: auth.meta.totp_secret,
guardrails: createGuardrails({
MIN_SECRET_BYTES: 10,
}),
});

if (!result.valid) {
// Accept either a TOTP code or one of the backup/recovery codes, using the
// same verification path as login. Passing a backup code straight to otplib's
// verify() throws ("Token must contain only digits"), which previously surfaced
// as an "Internal error" and left users who only had their recovery codes
// unable to disable 2FA (see #5451).
const valid = await internal2fa.verifyForLogin(userId, code);

if (!valid) {
throw new errs.AuthError("Invalid verification code");
}

Expand Down