1
0
mirror of https://github.com/bitwarden/jslib synced 2025-12-23 03:33:29 +00:00

[bug] Ensure all storage locations are cleared on state clean

This commit is contained in:
addison
2021-11-16 12:42:39 -05:00
parent ba7d7f1028
commit e7dce3e587

View File

@@ -78,9 +78,10 @@ export class StateService implements StateServiceAbstraction {
}
async clean(options?: StorageOptions): Promise<void> {
await this.secureStorageService.remove(options?.userId ?? this.state.activeUserId);
await this.storageService.remove(options?.userId ?? this.state.activeUserId);
delete this.state.accounts[options?.userId ?? this.state.activeUserId];
await this.removeAccountFromSessionStorage(options?.userId);
await this.removeAccountFromLocalStorage(options?.userId);
await this.removeAccountFromSecureStorage(options?.userId);
this.removeAccountFromMemory(options?.userId);
await this.pushAccounts();
}
@@ -1390,4 +1391,38 @@ export class StateService implements StateServiceAbstraction {
const state = await this.storageService.get<State>('state', await this.defaultOnDiskOptions());
return state?.activeUserId;
}
private async removeAccountFromLocalStorage(userId: string): Promise<void> {
const state = await this.secureStorageService.get<State>('state', { htmlStorageLocation: HtmlStorageLocation.Local });
if (state?.accounts[userId ?? this.state.activeUserId] == null) {
return;
}
delete state.accounts[userId ?? this.state.activeUserId]
await this.storageService.save('state', state, { htmlStorageLocation: HtmlStorageLocation.Local });
}
private async removeAccountFromSessionStorage(userId: string): Promise<void> {
const state = await this.secureStorageService.get<State>('state', { htmlStorageLocation: HtmlStorageLocation.Session });
if (state?.accounts[userId ?? this.state.activeUserId] == null) {
return;
}
delete state.accounts[userId ?? this.state.activeUserId]
await this.storageService.save('state', state, { htmlStorageLocation: HtmlStorageLocation.Session });
}
private async removeAccountFromSecureStorage(userId: string): Promise<void> {
const state = await this.secureStorageService.get<State>('state');
if (state?.accounts[userId ?? this.state.activeUserId] == null) {
return;
}
delete state.accounts[userId ?? this.state.activeUserId]
await this.secureStorageService.save('state', state);
}
private removeAccountFromMemory(userId: string): void {
if (this.state?.accounts[userId ?? this.state.activeUserId] == null) {
return;
}
delete this.state.accounts[userId ?? this.state.activeUserId];
}
}