mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 10:13:31 +00:00
[Auto-Logout] Implement Vault Timeout Options (#1194)
* Update jslib31a2574->28e3fff* Initial commit for vault timeout * Updated timeout/action retrieval in idle.background * Cycle saved for idle check * Await async calls for lock/logout in idle bg * Updated lock vs log out conditional Co-authored-by: Vincent Salucci <vsalucci@bitwarden.com>
This commit is contained in:
@@ -4,9 +4,9 @@ import MainBackground from './main.background';
|
||||
|
||||
import { Analytics } from 'jslib/misc';
|
||||
|
||||
import { LockService } from 'jslib/abstractions/lock.service';
|
||||
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
|
||||
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||
import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service';
|
||||
|
||||
export default class CommandsBackground {
|
||||
private isSafari: boolean;
|
||||
@@ -15,7 +15,7 @@ export default class CommandsBackground {
|
||||
|
||||
constructor(private main: MainBackground, private passwordGenerationService: PasswordGenerationService,
|
||||
private platformUtilsService: PlatformUtilsService, private analytics: Analytics,
|
||||
private lockService: LockService) {
|
||||
private vaultTimeoutService: VaultTimeoutService) {
|
||||
this.isSafari = this.platformUtilsService.isSafari();
|
||||
this.isEdge = this.platformUtilsService.isEdge();
|
||||
this.isVivaldi = this.platformUtilsService.isVivaldi();
|
||||
@@ -69,7 +69,7 @@ export default class CommandsBackground {
|
||||
}
|
||||
|
||||
private async autoFillLogin(tab?: any) {
|
||||
if (await this.lockService.isLocked()) {
|
||||
if (await this.vaultTimeoutService.isLocked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,10 @@ import { Analytics } from 'jslib/misc';
|
||||
|
||||
import { CipherService } from 'jslib/abstractions/cipher.service';
|
||||
import { EventService } from 'jslib/abstractions/event.service';
|
||||
import { LockService } from 'jslib/abstractions/lock.service';
|
||||
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
|
||||
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||
import { TotpService } from 'jslib/abstractions/totp.service';
|
||||
import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service';
|
||||
|
||||
import { EventType } from 'jslib/enums/eventType';
|
||||
|
||||
@@ -18,7 +18,7 @@ export default class ContextMenusBackground {
|
||||
|
||||
constructor(private main: MainBackground, private cipherService: CipherService,
|
||||
private passwordGenerationService: PasswordGenerationService, private analytics: Analytics,
|
||||
private platformUtilsService: PlatformUtilsService, private lockService: LockService,
|
||||
private platformUtilsService: PlatformUtilsService, private vaultTimeoutService: VaultTimeoutService,
|
||||
private eventService: EventService, private totpService: TotpService) {
|
||||
this.contextMenus = chrome.contextMenus;
|
||||
}
|
||||
@@ -61,7 +61,7 @@ export default class ContextMenusBackground {
|
||||
return;
|
||||
}
|
||||
|
||||
if (await this.lockService.isLocked()) {
|
||||
if (await this.vaultTimeoutService.isLocked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { ConstantsService } from 'jslib/services/constants.service';
|
||||
|
||||
import {
|
||||
LockService,
|
||||
StorageService,
|
||||
VaultTimeoutService,
|
||||
} from 'jslib/abstractions';
|
||||
import { NotificationsService } from 'jslib/abstractions/notifications.service';
|
||||
|
||||
@@ -13,7 +13,7 @@ export default class IdleBackground {
|
||||
private idleTimer: number = null;
|
||||
private idleState = 'active';
|
||||
|
||||
constructor(private lockService: LockService, private storageService: StorageService,
|
||||
constructor(private vaultTimeoutService: VaultTimeoutService, private storageService: StorageService,
|
||||
private notificationsService: NotificationsService) {
|
||||
this.idle = chrome.idle || (browser != null ? browser.idle : null);
|
||||
}
|
||||
@@ -39,10 +39,15 @@ export default class IdleBackground {
|
||||
|
||||
if (this.idle.onStateChanged) {
|
||||
this.idle.onStateChanged.addListener(async (newState: string) => {
|
||||
if (newState === 'locked') {
|
||||
const lockOption = await this.storageService.get<number>(ConstantsService.lockOptionKey);
|
||||
if (lockOption === -2) {
|
||||
this.lockService.lock(true);
|
||||
if (newState === 'locked') { // If the screen is locked or the screensaver activates
|
||||
const timeout = await this.storageService.get<number>(ConstantsService.vaultTimeoutKey);
|
||||
if (timeout === -2) { // On System Lock vault timeout option
|
||||
const action = await this.storageService.get<string>(ConstantsService.vaultTimeoutActionKey);
|
||||
if (action === 'lock') {
|
||||
await this.vaultTimeoutService.lock(true);
|
||||
} else {
|
||||
await this.vaultTimeoutService.logOut();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -11,13 +11,13 @@ import {
|
||||
CryptoService,
|
||||
EnvironmentService,
|
||||
FolderService,
|
||||
LockService,
|
||||
PasswordGenerationService,
|
||||
SettingsService,
|
||||
SyncService,
|
||||
TokenService,
|
||||
TotpService,
|
||||
UserService,
|
||||
VaultTimeoutService,
|
||||
} from 'jslib/services';
|
||||
import { EventService } from 'jslib/services/event.service';
|
||||
import { ExportService } from 'jslib/services/export.service';
|
||||
@@ -37,7 +37,6 @@ import {
|
||||
EnvironmentService as EnvironmentServiceAbstraction,
|
||||
FolderService as FolderServiceAbstraction,
|
||||
I18nService as I18nServiceAbstraction,
|
||||
LockService as LockServiceAbstraction,
|
||||
MessagingService as MessagingServiceAbstraction,
|
||||
PasswordGenerationService as PasswordGenerationServiceAbstraction,
|
||||
PlatformUtilsService as PlatformUtilsServiceAbstraction,
|
||||
@@ -47,6 +46,7 @@ import {
|
||||
TokenService as TokenServiceAbstraction,
|
||||
TotpService as TotpServiceAbstraction,
|
||||
UserService as UserServiceAbstraction,
|
||||
VaultTimeoutService as VaultTimeoutServiceAbstraction,
|
||||
} from 'jslib/abstractions';
|
||||
import { EventService as EventServiceAbstraction } from 'jslib/abstractions/event.service';
|
||||
import { ExportService as ExportServiceAbstraction } from 'jslib/abstractions/export.service';
|
||||
@@ -94,7 +94,7 @@ export default class MainBackground {
|
||||
cipherService: CipherServiceAbstraction;
|
||||
folderService: FolderServiceAbstraction;
|
||||
collectionService: CollectionServiceAbstraction;
|
||||
lockService: LockServiceAbstraction;
|
||||
vaultTimeoutService: VaultTimeoutServiceAbstraction;
|
||||
syncService: SyncServiceAbstraction;
|
||||
passwordGenerationService: PasswordGenerationServiceAbstraction;
|
||||
totpService: TotpServiceAbstraction;
|
||||
@@ -156,9 +156,9 @@ export default class MainBackground {
|
||||
this.i18nService);
|
||||
this.searchService = new SearchService(this.cipherService, this.platformUtilsService);
|
||||
this.policyService = new PolicyService(this.userService, this.storageService);
|
||||
this.lockService = new LockService(this.cipherService, this.folderService, this.collectionService,
|
||||
this.cryptoService, this.platformUtilsService, this.storageService, this.messagingService,
|
||||
this.searchService, this.userService, async () => {
|
||||
this.vaultTimeoutService = new VaultTimeoutService(this.cipherService, this.folderService,
|
||||
this.collectionService, this.cryptoService, this.platformUtilsService, this.storageService,
|
||||
this.messagingService, this.searchService, this.userService, async () => {
|
||||
if (this.notificationsService != null) {
|
||||
this.notificationsService.updateConnection(false);
|
||||
}
|
||||
@@ -168,7 +168,7 @@ export default class MainBackground {
|
||||
this.systemService.startProcessReload();
|
||||
await this.systemService.clearPendingClipboard();
|
||||
}
|
||||
});
|
||||
}, async () => await this.logout(false));
|
||||
this.syncService = new SyncService(this.userService, this.apiService, this.settingsService,
|
||||
this.folderService, this.cipherService, this.cryptoService, this.collectionService,
|
||||
this.storageService, this.messagingService, this.policyService,
|
||||
@@ -184,12 +184,12 @@ export default class MainBackground {
|
||||
this.auditService = new AuditService(cryptoFunctionService, this.apiService);
|
||||
this.exportService = new ExportService(this.folderService, this.cipherService, this.apiService);
|
||||
this.notificationsService = new NotificationsService(this.userService, this.syncService, this.appIdService,
|
||||
this.apiService, this.lockService, () => this.logout(true));
|
||||
this.apiService, this.vaultTimeoutService, () => this.logout(true));
|
||||
this.environmentService = new EnvironmentService(this.apiService, this.storageService,
|
||||
this.notificationsService);
|
||||
this.analytics = new Analytics(window, () => BrowserApi.gaFilter(), this.platformUtilsService,
|
||||
this.storageService, this.appIdService);
|
||||
this.systemService = new SystemService(this.storageService, this.lockService,
|
||||
this.systemService = new SystemService(this.storageService, this.vaultTimeoutService,
|
||||
this.messagingService, this.platformUtilsService, () => {
|
||||
const forceWindowReload = this.platformUtilsService.isSafari() ||
|
||||
this.platformUtilsService.isFirefox() || this.platformUtilsService.isOpera();
|
||||
@@ -205,18 +205,19 @@ export default class MainBackground {
|
||||
// Background
|
||||
this.runtimeBackground = new RuntimeBackground(this, this.autofillService, this.cipherService,
|
||||
this.platformUtilsService as BrowserPlatformUtilsService, this.storageService, this.i18nService,
|
||||
this.analytics, this.notificationsService, this.systemService, this.lockService);
|
||||
this.analytics, this.notificationsService, this.systemService, this.vaultTimeoutService);
|
||||
this.commandsBackground = new CommandsBackground(this, this.passwordGenerationService,
|
||||
this.platformUtilsService, this.analytics, this.lockService);
|
||||
this.platformUtilsService, this.analytics, this.vaultTimeoutService);
|
||||
|
||||
if (!this.isSafari) {
|
||||
this.tabsBackground = new TabsBackground(this);
|
||||
this.contextMenusBackground = new ContextMenusBackground(this, this.cipherService,
|
||||
this.passwordGenerationService, this.analytics, this.platformUtilsService, this.lockService,
|
||||
this.passwordGenerationService, this.analytics, this.platformUtilsService, this.vaultTimeoutService,
|
||||
this.eventService, this.totpService);
|
||||
this.idleBackground = new IdleBackground(this.lockService, this.storageService, this.notificationsService);
|
||||
this.idleBackground = new IdleBackground(this.vaultTimeoutService, this.storageService,
|
||||
this.notificationsService);
|
||||
this.webRequestBackground = new WebRequestBackground(this.platformUtilsService, this.cipherService,
|
||||
this.lockService);
|
||||
this.vaultTimeoutService);
|
||||
this.windowsBackground = new WindowsBackground(this);
|
||||
}
|
||||
}
|
||||
@@ -226,7 +227,7 @@ export default class MainBackground {
|
||||
this.analytics.ga('send', 'pageview', '/background.html');
|
||||
this.containerService.attachToWindow(window);
|
||||
|
||||
await (this.lockService as LockService).init(true);
|
||||
await (this.vaultTimeoutService as VaultTimeoutService).init(true);
|
||||
await (this.i18nService as I18nService).init();
|
||||
await (this.eventService as EventService).init(true);
|
||||
await this.runtimeBackground.init();
|
||||
@@ -258,7 +259,7 @@ export default class MainBackground {
|
||||
}
|
||||
|
||||
const isAuthenticated = await this.userService.isAuthenticated();
|
||||
const locked = await this.lockService.isLocked();
|
||||
const locked = await this.vaultTimeoutService.isLocked();
|
||||
|
||||
let suffix = '';
|
||||
if (!isAuthenticated) {
|
||||
@@ -311,7 +312,7 @@ export default class MainBackground {
|
||||
this.collectionService.clear(userId),
|
||||
this.policyService.clear(userId),
|
||||
this.passwordGenerationService.clear(),
|
||||
this.lockService.clear(),
|
||||
this.vaultTimeoutService.clear(),
|
||||
]);
|
||||
|
||||
this.searchService.clearIndex();
|
||||
@@ -330,7 +331,7 @@ export default class MainBackground {
|
||||
return;
|
||||
}
|
||||
|
||||
if (await this.lockService.isLocked()) {
|
||||
if (await this.vaultTimeoutService.isLocked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -378,8 +379,8 @@ export default class MainBackground {
|
||||
return;
|
||||
}
|
||||
|
||||
const currentLockOption = await this.storageService.get<number>(ConstantsService.lockOptionKey);
|
||||
if (currentLockOption == null) {
|
||||
const currentVaultTimeout = await this.storageService.get<number>(ConstantsService.vaultTimeoutKey);
|
||||
if (currentVaultTimeout == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -482,7 +483,7 @@ export default class MainBackground {
|
||||
this.actionSetBadgeBackgroundColor(this.sidebarAction);
|
||||
|
||||
this.menuOptionsLoaded = [];
|
||||
const locked = await this.lockService.isLocked();
|
||||
const locked = await this.vaultTimeoutService.isLocked();
|
||||
if (!locked) {
|
||||
try {
|
||||
const ciphers = await this.cipherService.getAllDecryptedForUrl(url);
|
||||
|
||||
@@ -11,9 +11,9 @@ import { I18nService } from 'jslib/abstractions/i18n.service';
|
||||
import { Analytics } from 'jslib/misc';
|
||||
|
||||
import { CipherService } from 'jslib/abstractions/cipher.service';
|
||||
import { LockService } from 'jslib/abstractions/lock.service';
|
||||
import { StorageService } from 'jslib/abstractions/storage.service';
|
||||
import { SystemService } from 'jslib/abstractions/system.service';
|
||||
import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service';
|
||||
|
||||
import { BrowserApi } from '../browser/browserApi';
|
||||
|
||||
@@ -37,7 +37,7 @@ export default class RuntimeBackground {
|
||||
private cipherService: CipherService, private platformUtilsService: BrowserPlatformUtilsService,
|
||||
private storageService: StorageService, private i18nService: I18nService,
|
||||
private analytics: Analytics, private notificationsService: NotificationsService,
|
||||
private systemService: SystemService, private lockService: LockService) {
|
||||
private systemService: SystemService, private vaultTimeoutService: VaultTimeoutService) {
|
||||
this.isSafari = this.platformUtilsService.isSafari();
|
||||
this.runtime = this.isSafari ? {} : chrome.runtime;
|
||||
|
||||
@@ -127,7 +127,7 @@ export default class RuntimeBackground {
|
||||
await this.main.reseedStorage();
|
||||
break;
|
||||
case 'collectPageDetailsResponse':
|
||||
if (await this.lockService.isLocked()) {
|
||||
if (await this.vaultTimeoutService.isLocked()) {
|
||||
return;
|
||||
}
|
||||
switch (msg.sender) {
|
||||
@@ -183,7 +183,7 @@ export default class RuntimeBackground {
|
||||
}
|
||||
|
||||
private async saveAddLogin(tab: any) {
|
||||
if (await this.lockService.isLocked()) {
|
||||
if (await this.vaultTimeoutService.isLocked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ export default class RuntimeBackground {
|
||||
}
|
||||
|
||||
private async saveChangePassword(tab: any) {
|
||||
if (await this.lockService.isLocked()) {
|
||||
if (await this.vaultTimeoutService.isLocked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -276,7 +276,7 @@ export default class RuntimeBackground {
|
||||
}
|
||||
|
||||
private async addLogin(loginInfo: any, tab: any) {
|
||||
if (await this.lockService.isLocked()) {
|
||||
if (await this.vaultTimeoutService.isLocked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -322,7 +322,7 @@ export default class RuntimeBackground {
|
||||
}
|
||||
|
||||
private async changedPassword(changeData: any, tab: any) {
|
||||
if (await this.lockService.isLocked()) {
|
||||
if (await this.vaultTimeoutService.isLocked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -400,10 +400,16 @@ export default class RuntimeBackground {
|
||||
}
|
||||
|
||||
private async setDefaultSettings() {
|
||||
// Default lock options to "on restart".
|
||||
const currentLockOption = await this.storageService.get<number>(ConstantsService.lockOptionKey);
|
||||
if (currentLockOption == null) {
|
||||
await this.storageService.save(ConstantsService.lockOptionKey, -1);
|
||||
// Default timeout option to "on restart".
|
||||
const currentVaultTimeout = await this.storageService.get<number>(ConstantsService.vaultTimeoutKey);
|
||||
if (currentVaultTimeout == null) {
|
||||
await this.storageService.save(ConstantsService.vaultTimeoutKey, -1);
|
||||
}
|
||||
|
||||
// Default action to "lock".
|
||||
const currentVaultTimeoutAction = await this.storageService.get<string>(ConstantsService.vaultTimeoutActionKey);
|
||||
if (currentVaultTimeoutAction == null) {
|
||||
await this.storageService.save(ConstantsService.vaultTimeoutActionKey, 'lock');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { CipherService } from 'jslib/abstractions/cipher.service';
|
||||
import { LockService } from 'jslib/abstractions/lock.service';
|
||||
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||
import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service';
|
||||
|
||||
export default class WebRequestBackground {
|
||||
private pendingAuthRequests: any[] = [];
|
||||
@@ -8,7 +8,7 @@ export default class WebRequestBackground {
|
||||
private isFirefox: boolean;
|
||||
|
||||
constructor(platformUtilsService: PlatformUtilsService, private cipherService: CipherService,
|
||||
private lockService: LockService) {
|
||||
private vaultTimeoutService: VaultTimeoutService) {
|
||||
this.webRequest = (window as any).chrome.webRequest;
|
||||
this.isFirefox = platformUtilsService.isFirefox();
|
||||
}
|
||||
@@ -44,7 +44,7 @@ export default class WebRequestBackground {
|
||||
}
|
||||
|
||||
private async resolveAuthCredentials(domain: string, success: Function, error: Function) {
|
||||
if (await this.lockService.isLocked()) {
|
||||
if (await this.vaultTimeoutService.isLocked()) {
|
||||
error();
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user