mirror of
https://github.com/bitwarden/browser.git
synced 2025-03-02 03:41:09 +01:00
only use memory storage for vault data keys (#650)
* only use memory storage for vault data keys * add lastSync_ to memory storage
This commit is contained in:
parent
ce67497d3a
commit
9f0cd586ee
@ -9,7 +9,8 @@ export class HtmlStorageService implements StorageService {
|
|||||||
ConstantsService.vaultTimeoutKey, ConstantsService.vaultTimeoutActionKey, ConstantsService.ssoCodeVerifierKey,
|
ConstantsService.vaultTimeoutKey, ConstantsService.vaultTimeoutActionKey, ConstantsService.ssoCodeVerifierKey,
|
||||||
ConstantsService.ssoStateKey, 'ssoOrgIdentifier']);
|
ConstantsService.ssoStateKey, 'ssoOrgIdentifier']);
|
||||||
private localStorageStartsWithKeys = ['twoFactorToken_', ConstantsService.collapsedGroupingsKey + '_'];
|
private localStorageStartsWithKeys = ['twoFactorToken_', ConstantsService.collapsedGroupingsKey + '_'];
|
||||||
private sessionMemoryStorage = new Map<string, string>()
|
private memoryStorageStartsWithKeys = ['ciphers_', 'folders_', 'collections_', 'settings_', 'lastSync_'];
|
||||||
|
private memoryStorage = new Map<string, string>()
|
||||||
|
|
||||||
constructor(private platformUtilsService: PlatformUtilsService) { }
|
constructor(private platformUtilsService: PlatformUtilsService) { }
|
||||||
|
|
||||||
@ -31,8 +32,10 @@ export class HtmlStorageService implements StorageService {
|
|||||||
let json: string = null;
|
let json: string = null;
|
||||||
if (this.isLocalStorage(key)) {
|
if (this.isLocalStorage(key)) {
|
||||||
json = window.localStorage.getItem(key);
|
json = window.localStorage.getItem(key);
|
||||||
|
} else if (this.isMemoryStorage(key)) {
|
||||||
|
json = this.memoryStorage.get(key);
|
||||||
} else {
|
} else {
|
||||||
json = this.sessionMemoryStorage.get(key);
|
json = window.sessionStorage.getItem(key);
|
||||||
}
|
}
|
||||||
if (json != null) {
|
if (json != null) {
|
||||||
const obj = JSON.parse(json);
|
const obj = JSON.parse(json);
|
||||||
@ -49,8 +52,10 @@ export class HtmlStorageService implements StorageService {
|
|||||||
const json = JSON.stringify(obj);
|
const json = JSON.stringify(obj);
|
||||||
if (this.isLocalStorage(key)) {
|
if (this.isLocalStorage(key)) {
|
||||||
window.localStorage.setItem(key, json);
|
window.localStorage.setItem(key, json);
|
||||||
|
} else if (this.isMemoryStorage(key)) {
|
||||||
|
this.memoryStorage.set(key, json);
|
||||||
} else {
|
} else {
|
||||||
this.sessionMemoryStorage.set(key, json);
|
window.sessionStorage.setItem(key, json);
|
||||||
}
|
}
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
@ -58,8 +63,10 @@ export class HtmlStorageService implements StorageService {
|
|||||||
remove(key: string): Promise<any> {
|
remove(key: string): Promise<any> {
|
||||||
if (this.isLocalStorage(key)) {
|
if (this.isLocalStorage(key)) {
|
||||||
window.localStorage.removeItem(key);
|
window.localStorage.removeItem(key);
|
||||||
|
} else if (this.isMemoryStorage(key)) {
|
||||||
|
this.memoryStorage.delete(key);
|
||||||
} else {
|
} else {
|
||||||
this.sessionMemoryStorage.delete(key);
|
window.sessionStorage.removeItem(key);
|
||||||
}
|
}
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
@ -75,4 +82,13 @@ export class HtmlStorageService implements StorageService {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private isMemoryStorage(key: string): boolean {
|
||||||
|
for (const swKey of this.memoryStorageStartsWithKeys) {
|
||||||
|
if (key.startsWith(swKey)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user