1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-03 08:49:50 +01:00

Open notificationBar (new and existing login) even though vault is locked

This commit is contained in:
Daniel James Smith 2021-09-30 16:03:14 +02:00
parent 889bbf8e2f
commit 210e0801ff
No known key found for this signature in database
GPG Key ID: 03E4BD365FF06726
3 changed files with 57 additions and 21 deletions

View File

@ -0,0 +1,9 @@
export default class addChangePasswordQueueMessage {
type: string;
cipherId: string;
newPassword: string;
domain: string;
tabId: string;
expires: Date;
wasVaultLocked: boolean;
}

View File

@ -0,0 +1,10 @@
export default class addLoginQueueMessage {
type: string;
username: string;
password: string;
domain: string;
uri: string;
tabId: string;
expires: Date;
wasVaultLocked: boolean;
}

View File

@ -27,6 +27,9 @@ import { Utils } from 'jslib-common/misc/utils';
import { PolicyType } from 'jslib-common/enums/policyType'; import { PolicyType } from 'jslib-common/enums/policyType';
import addChangePasswordQueueMessage from './models/addChangePasswordQueueMessage';
import addLoginQueueMessage from './models/addLoginQueueMessage';
export default class RuntimeBackground { export default class RuntimeBackground {
private runtime: any; private runtime: any;
private autofillTimeout: any; private autofillTimeout: any;
@ -217,6 +220,7 @@ export default class RuntimeBackground {
} }
private async saveAddLogin(tab: any, folderId: string) { private async saveAddLogin(tab: any, folderId: string) {
console.log('saveAddLogin triggered');
if (await this.vaultTimeoutService.isLocked()) { if (await this.vaultTimeoutService.isLocked()) {
return; return;
} }
@ -260,6 +264,7 @@ export default class RuntimeBackground {
} }
private async saveChangePassword(tab: any) { private async saveChangePassword(tab: any) {
console.log('saveChangePassword triggered');
if (await this.vaultTimeoutService.isLocked()) { if (await this.vaultTimeoutService.isLocked()) {
return; return;
} }
@ -309,10 +314,7 @@ export default class RuntimeBackground {
} }
private async addLogin(loginInfo: any, tab: any) { private async addLogin(loginInfo: any, tab: any) {
if (await this.vaultTimeoutService.isLocked()) { console.log('addLogin triggered');
return;
}
const loginDomain = Utils.getDomain(loginInfo.url); const loginDomain = Utils.getDomain(loginInfo.url);
if (loginDomain == null) { if (loginDomain == null) {
return; return;
@ -323,6 +325,11 @@ export default class RuntimeBackground {
normalizedUsername = normalizedUsername.toLowerCase(); normalizedUsername = normalizedUsername.toLowerCase();
} }
if (await this.vaultTimeoutService.isLocked()) {
this.pushAddLoginToQueue(loginDomain, loginInfo, tab, true);
return;
}
const ciphers = await this.cipherService.getAllDecryptedForUrl(loginInfo.url); const ciphers = await this.cipherService.getAllDecryptedForUrl(loginInfo.url);
const usernameMatches = ciphers.filter(c => const usernameMatches = ciphers.filter(c =>
c.login.username != null && c.login.username.toLowerCase() === normalizedUsername); c.login.username != null && c.login.username.toLowerCase() === normalizedUsername);
@ -337,9 +344,22 @@ export default class RuntimeBackground {
return; return;
} }
this.pushAddLoginToQueue(loginDomain, loginInfo, tab);
} else if (usernameMatches.length === 1 && usernameMatches[0].login.password !== loginInfo.password) {
const disabledChangePassword = await this.storageService.get<boolean>(
ConstantsService.disableChangedPasswordNotificationKey);
if (disabledChangePassword) {
return;
}
this.pushChangePasswordToQueue(usernameMatches[0].id, loginDomain, loginInfo.password, tab);
}
}
private async pushAddLoginToQueue(loginDomain: string, loginInfo: any, tab: any, isVaultLocked: boolean = false) {
// remove any old messages for this tab // remove any old messages for this tab
this.removeTabFromNotificationQueue(tab); this.removeTabFromNotificationQueue(tab);
this.main.notificationQueue.push({ const message: addLoginQueueMessage = {
type: 'addLogin', type: 'addLogin',
username: loginInfo.username, username: loginInfo.username,
password: loginInfo.password, password: loginInfo.password,
@ -347,25 +367,20 @@ export default class RuntimeBackground {
uri: loginInfo.url, uri: loginInfo.url,
tabId: tab.id, tabId: tab.id,
expires: new Date((new Date()).getTime() + 30 * 60000), // 30 minutes expires: new Date((new Date()).getTime() + 30 * 60000), // 30 minutes
}); wasVaultLocked: isVaultLocked,
};
this.main.notificationQueue.push(message);
await this.main.checkNotificationQueue(tab); await this.main.checkNotificationQueue(tab);
} else if (usernameMatches.length === 1 && usernameMatches[0].login.password !== loginInfo.password) {
const disabledChangePassword = await this.storageService.get<boolean>(
ConstantsService.disableChangedPasswordNotificationKey);
if (disabledChangePassword) {
return;
}
this.addChangedPasswordToQueue(usernameMatches[0].id, loginDomain, loginInfo.password, tab);
}
} }
private async changedPassword(changeData: any, tab: any) { private async changedPassword(changeData: any, tab: any) {
if (await this.vaultTimeoutService.isLocked()) { const loginDomain = Utils.getDomain(changeData.url);
if (loginDomain == null) {
return; return;
} }
const loginDomain = Utils.getDomain(changeData.url); if (await this.vaultTimeoutService.isLocked()) {
if (loginDomain == null) { this.pushChangePasswordToQueue(null, loginDomain, changeData.newPassword, tab, true);
return; return;
} }
@ -380,21 +395,23 @@ export default class RuntimeBackground {
id = ciphers[0].id; id = ciphers[0].id;
} }
if (id != null) { if (id != null) {
this.addChangedPasswordToQueue(id, loginDomain, changeData.newPassword, tab); this.pushChangePasswordToQueue(id, loginDomain, changeData.newPassword, tab);
} }
} }
private async addChangedPasswordToQueue(cipherId: string, loginDomain: string, newPassword: string, tab: any) { private async pushChangePasswordToQueue(cipherId: string, loginDomain: string, newPassword: string, tab: any, isVaultLocked: boolean = false) {
// remove any old messages for this tab // remove any old messages for this tab
this.removeTabFromNotificationQueue(tab); this.removeTabFromNotificationQueue(tab);
this.main.notificationQueue.push({ const message: addChangePasswordQueueMessage = {
type: 'changePassword', type: 'changePassword',
cipherId: cipherId, cipherId: cipherId,
newPassword: newPassword, newPassword: newPassword,
domain: loginDomain, domain: loginDomain,
tabId: tab.id, tabId: tab.id,
expires: new Date((new Date()).getTime() + 30 * 60000), // 30 minutes expires: new Date((new Date()).getTime() + 30 * 60000), // 30 minutes
}); wasVaultLocked: isVaultLocked,
};
this.main.notificationQueue.push(message);
await this.main.checkNotificationQueue(tab); await this.main.checkNotificationQueue(tab);
} }