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

API / Auth: Require OTP if Enforce TFA is enabled #22190

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions api/src/services/authentication.ts
Expand Up @@ -72,7 +72,7 @@ export class AuthenticationService {
}

const user = await this.knex
.select<User & { tfa_secret: string | null }>(
.select<User & { tfa_secret: string | null; enforce_tfa: boolean | null }>(
'u.id',
'u.first_name',
'u.last_name',
Expand All @@ -82,6 +82,7 @@ export class AuthenticationService {
'u.role',
'r.admin_access',
'r.app_access',
'r.enforce_tfa',
'u.tfa_secret',
'u.provider',
'u.external_identifier',
Expand Down Expand Up @@ -177,7 +178,10 @@ export class AuthenticationService {
throw e;
}

if (user.tfa_secret && !options?.otp) {
const requiresTfa = user.enforce_tfa || user.tfa_secret;
const hasTfa = user.tfa_secret && options?.otp;

if (requiresTfa && !hasTfa) {
emitStatus('fail');
await stall(STALL_TIME, timeStart);
throw new InvalidOtpError();
Expand Down