mirror of
https://github.com/bitwarden/browser
synced 2025-12-11 13:53:34 +00:00
revert: [PR-13659] remove 2FA timeout logging and fix attempts
This reverts two previous commits: - PM-13659 - 2FA Timeout Log All the things (#12275) - Auth/PM-13659 - 2FA Timeout - Attempted Fix (#12263)
This commit is contained in:
@@ -17,7 +17,6 @@ import {
|
|||||||
PinService,
|
PinService,
|
||||||
PinServiceAbstraction,
|
PinServiceAbstraction,
|
||||||
UserDecryptionOptionsService,
|
UserDecryptionOptionsService,
|
||||||
Executor,
|
|
||||||
} from "@bitwarden/auth/common";
|
} from "@bitwarden/auth/common";
|
||||||
import { EventCollectionService as EventCollectionServiceAbstraction } from "@bitwarden/common/abstractions/event/event-collection.service";
|
import { EventCollectionService as EventCollectionServiceAbstraction } from "@bitwarden/common/abstractions/event/event-collection.service";
|
||||||
import { EventUploadService as EventUploadServiceAbstraction } from "@bitwarden/common/abstractions/event/event-upload.service";
|
import { EventUploadService as EventUploadServiceAbstraction } from "@bitwarden/common/abstractions/event/event-upload.service";
|
||||||
@@ -615,11 +614,6 @@ export class ServiceContainer {
|
|||||||
this.configService,
|
this.configService,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Execute any authn session timeout logic without any wrapping logic.
|
|
||||||
// An executor is required to ensure the logic is executed in an Angular context when it
|
|
||||||
// it is available.
|
|
||||||
const authnSessionTimeoutExecutor: Executor = (fn) => fn();
|
|
||||||
|
|
||||||
this.loginStrategyService = new LoginStrategyService(
|
this.loginStrategyService = new LoginStrategyService(
|
||||||
this.accountService,
|
this.accountService,
|
||||||
this.masterPasswordService,
|
this.masterPasswordService,
|
||||||
@@ -646,7 +640,6 @@ export class ServiceContainer {
|
|||||||
this.vaultTimeoutSettingsService,
|
this.vaultTimeoutSettingsService,
|
||||||
this.kdfConfigService,
|
this.kdfConfigService,
|
||||||
this.taskSchedulerService,
|
this.taskSchedulerService,
|
||||||
authnSessionTimeoutExecutor,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// FIXME: CLI does not support autofill
|
// FIXME: CLI does not support autofill
|
||||||
|
|||||||
@@ -102,20 +102,10 @@ export class TwoFactorComponent extends CaptchaProtectedComponent implements OnI
|
|||||||
super(environmentService, i18nService, platformUtilsService, toastService);
|
super(environmentService, i18nService, platformUtilsService, toastService);
|
||||||
this.webAuthnSupported = this.platformUtilsService.supportsWebAuthn(win);
|
this.webAuthnSupported = this.platformUtilsService.supportsWebAuthn(win);
|
||||||
|
|
||||||
this.logService.info(
|
|
||||||
"Subscribing to timeout on LoginStrategyService with service id: " +
|
|
||||||
this.loginStrategyService.id,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Add subscription to twoFactorTimeout$ and navigate to twoFactorTimeoutRoute if expired
|
// Add subscription to twoFactorTimeout$ and navigate to twoFactorTimeoutRoute if expired
|
||||||
this.loginStrategyService.twoFactorTimeout$
|
this.loginStrategyService.twoFactorTimeout$
|
||||||
.pipe(takeUntilDestroyed())
|
.pipe(takeUntilDestroyed())
|
||||||
.subscribe(async (expired) => {
|
.subscribe(async (expired) => {
|
||||||
this.logService.info(
|
|
||||||
"Received emission from LoginStrategyService.twoFactorTimeout$ with service id: " +
|
|
||||||
this.loginStrategyService.id,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!expired) {
|
if (!expired) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { InjectionToken } from "@angular/core";
|
import { InjectionToken } from "@angular/core";
|
||||||
import { Observable, Subject } from "rxjs";
|
import { Observable, Subject } from "rxjs";
|
||||||
|
|
||||||
import { Executor, LogoutReason } from "@bitwarden/auth/common";
|
import { LogoutReason } from "@bitwarden/auth/common";
|
||||||
import { ClientType } from "@bitwarden/common/enums";
|
import { ClientType } from "@bitwarden/common/enums";
|
||||||
import { RegionConfig } from "@bitwarden/common/platform/abstractions/environment.service";
|
import { RegionConfig } from "@bitwarden/common/platform/abstractions/environment.service";
|
||||||
import {
|
import {
|
||||||
@@ -68,7 +68,3 @@ export const REFRESH_ACCESS_TOKEN_ERROR_CALLBACK = new SafeInjectionToken<() =>
|
|||||||
export const ENV_ADDITIONAL_REGIONS = new SafeInjectionToken<RegionConfig[]>(
|
export const ENV_ADDITIONAL_REGIONS = new SafeInjectionToken<RegionConfig[]>(
|
||||||
"ENV_ADDITIONAL_REGIONS",
|
"ENV_ADDITIONAL_REGIONS",
|
||||||
);
|
);
|
||||||
|
|
||||||
export const AUTHN_SESSION_TIMEOUT_EXECUTOR = new SafeInjectionToken<Executor>(
|
|
||||||
"AuthnSessionTimeoutExecutor",
|
|
||||||
);
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ErrorHandler, LOCALE_ID, NgModule, NgZone } from "@angular/core";
|
import { ErrorHandler, LOCALE_ID, NgModule } from "@angular/core";
|
||||||
import { Subject } from "rxjs";
|
import { Subject } from "rxjs";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -319,7 +319,6 @@ import {
|
|||||||
CLIENT_TYPE,
|
CLIENT_TYPE,
|
||||||
REFRESH_ACCESS_TOKEN_ERROR_CALLBACK,
|
REFRESH_ACCESS_TOKEN_ERROR_CALLBACK,
|
||||||
ENV_ADDITIONAL_REGIONS,
|
ENV_ADDITIONAL_REGIONS,
|
||||||
AUTHN_SESSION_TIMEOUT_EXECUTOR,
|
|
||||||
} from "./injection-tokens";
|
} from "./injection-tokens";
|
||||||
import { ModalService } from "./modal.service";
|
import { ModalService } from "./modal.service";
|
||||||
|
|
||||||
@@ -412,11 +411,6 @@ const safeProviders: SafeProvider[] = [
|
|||||||
TokenServiceAbstraction,
|
TokenServiceAbstraction,
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
safeProvider({
|
|
||||||
provide: AUTHN_SESSION_TIMEOUT_EXECUTOR,
|
|
||||||
useFactory: (ngZone: NgZone) => (fn: () => void) => ngZone.run(fn),
|
|
||||||
deps: [NgZone],
|
|
||||||
}),
|
|
||||||
safeProvider({
|
safeProvider({
|
||||||
provide: LoginStrategyServiceAbstraction,
|
provide: LoginStrategyServiceAbstraction,
|
||||||
useClass: LoginStrategyService,
|
useClass: LoginStrategyService,
|
||||||
@@ -446,7 +440,6 @@ const safeProviders: SafeProvider[] = [
|
|||||||
VaultTimeoutSettingsServiceAbstraction,
|
VaultTimeoutSettingsServiceAbstraction,
|
||||||
KdfConfigService,
|
KdfConfigService,
|
||||||
TaskSchedulerService,
|
TaskSchedulerService,
|
||||||
AUTHN_SESSION_TIMEOUT_EXECUTOR,
|
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
safeProvider({
|
safeProvider({
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ import {
|
|||||||
} from "../models/domain/login-credentials";
|
} from "../models/domain/login-credentials";
|
||||||
|
|
||||||
export abstract class LoginStrategyServiceAbstraction {
|
export abstract class LoginStrategyServiceAbstraction {
|
||||||
id: string;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current strategy being used to authenticate.
|
* The current strategy being used to authenticate.
|
||||||
* Emits null if the session has timed out.
|
* Emits null if the session has timed out.
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import {
|
|||||||
shareReplay,
|
shareReplay,
|
||||||
Subscription,
|
Subscription,
|
||||||
BehaviorSubject,
|
BehaviorSubject,
|
||||||
tap,
|
|
||||||
} from "rxjs";
|
} from "rxjs";
|
||||||
|
|
||||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||||
@@ -32,7 +31,6 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service"
|
|||||||
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
||||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||||
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
|
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
|
||||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
|
||||||
import { TaskSchedulerService, ScheduledTaskNames } from "@bitwarden/common/platform/scheduling";
|
import { TaskSchedulerService, ScheduledTaskNames } from "@bitwarden/common/platform/scheduling";
|
||||||
import { GlobalState, GlobalStateProvider } from "@bitwarden/common/platform/state";
|
import { GlobalState, GlobalStateProvider } from "@bitwarden/common/platform/state";
|
||||||
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/src/auth/abstractions/device-trust.service.abstraction";
|
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/src/auth/abstractions/device-trust.service.abstraction";
|
||||||
@@ -73,8 +71,6 @@ import {
|
|||||||
|
|
||||||
const sessionTimeoutLength = 5 * 60 * 1000; // 5 minutes
|
const sessionTimeoutLength = 5 * 60 * 1000; // 5 minutes
|
||||||
|
|
||||||
export type Executor = (fn: () => void) => void;
|
|
||||||
|
|
||||||
export class LoginStrategyService implements LoginStrategyServiceAbstraction {
|
export class LoginStrategyService implements LoginStrategyServiceAbstraction {
|
||||||
private sessionTimeoutSubscription: Subscription;
|
private sessionTimeoutSubscription: Subscription;
|
||||||
private currentAuthnTypeState: GlobalState<AuthenticationType | null>;
|
private currentAuthnTypeState: GlobalState<AuthenticationType | null>;
|
||||||
@@ -83,36 +79,7 @@ export class LoginStrategyService implements LoginStrategyServiceAbstraction {
|
|||||||
private authRequestPushNotificationState: GlobalState<string>;
|
private authRequestPushNotificationState: GlobalState<string>;
|
||||||
private twoFactorTimeoutSubject = new BehaviorSubject<boolean>(false);
|
private twoFactorTimeoutSubject = new BehaviorSubject<boolean>(false);
|
||||||
|
|
||||||
twoFactorTimeout$: Observable<boolean> = this.twoFactorTimeoutSubject.asObservable().pipe(
|
twoFactorTimeout$: Observable<boolean> = this.twoFactorTimeoutSubject.asObservable();
|
||||||
// line 87 is the tap?
|
|
||||||
tap({
|
|
||||||
next: (value) => {
|
|
||||||
this.logService.info(
|
|
||||||
`LoginStrategyService.twoFactorTimeout$ with service id: ${this.id} emmitted value: ${value}`,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
error: (error: unknown) => {
|
|
||||||
this.logService.error(
|
|
||||||
`LoginStrategyService.twoFactorTimeout$ with service id: ${this.id} errored with error: ${JSON.stringify(error)}`,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
finalize: () => {
|
|
||||||
this.logService.info(
|
|
||||||
`LoginStrategyService.twoFactorTimeout$ with service id: ${this.id} finalized`,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
complete: () => {
|
|
||||||
this.logService.info(
|
|
||||||
`LoginStrategyService.twoFactorTimeout$ with service id: ${this.id} completed`,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
subscribe: () => {
|
|
||||||
this.logService.info(
|
|
||||||
`LoginStrategyService.twoFactorTimeout$ with service id: ${this.id} subscribed`,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
private loginStrategy$: Observable<
|
private loginStrategy$: Observable<
|
||||||
| UserApiLoginStrategy
|
| UserApiLoginStrategy
|
||||||
@@ -125,8 +92,6 @@ export class LoginStrategyService implements LoginStrategyServiceAbstraction {
|
|||||||
|
|
||||||
currentAuthType$: Observable<AuthenticationType | null>;
|
currentAuthType$: Observable<AuthenticationType | null>;
|
||||||
|
|
||||||
id: string = Utils.newGuid();
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
protected accountService: AccountService,
|
protected accountService: AccountService,
|
||||||
protected masterPasswordService: InternalMasterPasswordServiceAbstraction,
|
protected masterPasswordService: InternalMasterPasswordServiceAbstraction,
|
||||||
@@ -153,7 +118,6 @@ export class LoginStrategyService implements LoginStrategyServiceAbstraction {
|
|||||||
protected vaultTimeoutSettingsService: VaultTimeoutSettingsService,
|
protected vaultTimeoutSettingsService: VaultTimeoutSettingsService,
|
||||||
protected kdfConfigService: KdfConfigService,
|
protected kdfConfigService: KdfConfigService,
|
||||||
protected taskSchedulerService: TaskSchedulerService,
|
protected taskSchedulerService: TaskSchedulerService,
|
||||||
private authnSessionTimeoutExecutor: Executor = (fn) => fn(), // Default to no-op
|
|
||||||
) {
|
) {
|
||||||
this.currentAuthnTypeState = this.stateProvider.get(CURRENT_LOGIN_STRATEGY_KEY);
|
this.currentAuthnTypeState = this.stateProvider.get(CURRENT_LOGIN_STRATEGY_KEY);
|
||||||
this.loginStrategyCacheState = this.stateProvider.get(CACHE_KEY);
|
this.loginStrategyCacheState = this.stateProvider.get(CACHE_KEY);
|
||||||
@@ -164,15 +128,12 @@ export class LoginStrategyService implements LoginStrategyServiceAbstraction {
|
|||||||
this.taskSchedulerService.registerTaskHandler(
|
this.taskSchedulerService.registerTaskHandler(
|
||||||
ScheduledTaskNames.loginStrategySessionTimeout,
|
ScheduledTaskNames.loginStrategySessionTimeout,
|
||||||
async () => {
|
async () => {
|
||||||
this.logService.info("Timeout executing for LoginStrategyService with id: " + this.id);
|
this.twoFactorTimeoutSubject.next(true);
|
||||||
this.authnSessionTimeoutExecutor(async () => {
|
try {
|
||||||
this.twoFactorTimeoutSubject.next(true);
|
await this.clearCache();
|
||||||
try {
|
} catch (e) {
|
||||||
await this.clearCache();
|
this.logService.error("Failed to clear cache during session timeout", e);
|
||||||
} catch (e) {
|
}
|
||||||
this.logService.error("Failed to clear cache during session timeout", e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user