1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-20 18:23:31 +00:00

JSON stringify memory items (#7731)

* JSON stringify memory items

stringification is required so they can be reliably sent through messaging

* Simplify null handling
This commit is contained in:
Matt Gibson
2024-01-29 14:42:58 -05:00
committed by GitHub
parent 76183c839a
commit 1da6733e71
9 changed files with 150 additions and 17 deletions

View File

@@ -51,6 +51,7 @@ import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from "@bitwar
import {
AbstractMemoryStorageService,
AbstractStorageService,
ObservableStorageService,
} from "@bitwarden/common/platform/abstractions/storage.service";
import { SystemService as SystemServiceAbstraction } from "@bitwarden/common/platform/abstractions/system.service";
import { StateFactory } from "@bitwarden/common/platform/factories/state-factory";
@@ -62,6 +63,7 @@ import { ContainerService } from "@bitwarden/common/platform/services/container.
import { EncryptServiceImplementation } from "@bitwarden/common/platform/services/cryptography/encrypt.service.implementation";
import { MultithreadEncryptServiceImplementation } from "@bitwarden/common/platform/services/cryptography/multithread-encrypt.service.implementation";
import { FileUploadService } from "@bitwarden/common/platform/services/file-upload/file-upload.service";
import { MemoryStorageService } from "@bitwarden/common/platform/services/memory-storage.service";
import { SystemService } from "@bitwarden/common/platform/services/system.service";
import { WebCryptoFunctionService } from "@bitwarden/common/platform/services/web-crypto-function.service";
import {
@@ -188,6 +190,7 @@ export default class MainBackground {
storageService: AbstractStorageService;
secureStorageService: AbstractStorageService;
memoryStorageService: AbstractMemoryStorageService;
memoryStorageForStateProviders: AbstractMemoryStorageService & ObservableStorageService;
i18nService: I18nServiceAbstraction;
platformUtilsService: PlatformUtilsServiceAbstraction;
logService: LogServiceAbstraction;
@@ -309,6 +312,13 @@ export default class MainBackground {
this.storageService = new BrowserLocalStorageService();
this.secureStorageService = new BrowserLocalStorageService();
this.memoryStorageService =
BrowserApi.manifestVersion === 3
? new LocalBackedSessionStorageService(
new EncryptServiceImplementation(this.cryptoFunctionService, this.logService, false),
new KeyGenerationService(this.cryptoFunctionService),
)
: new MemoryStorageService();
this.memoryStorageForStateProviders =
BrowserApi.manifestVersion === 3
? new LocalBackedSessionStorageService(
new EncryptServiceImplementation(this.cryptoFunctionService, this.logService, false),
@@ -316,7 +326,7 @@ export default class MainBackground {
)
: new BackgroundMemoryStorageService();
this.globalStateProvider = new DefaultGlobalStateProvider(
this.memoryStorageService as BackgroundMemoryStorageService,
this.memoryStorageForStateProviders,
this.storageService as BrowserLocalStorageService,
);
this.encryptService = flagEnabled("multithreadDecryption")
@@ -328,7 +338,7 @@ export default class MainBackground {
: new EncryptServiceImplementation(this.cryptoFunctionService, this.logService, true);
this.singleUserStateProvider = new DefaultSingleUserStateProvider(
this.memoryStorageService as BackgroundMemoryStorageService,
this.memoryStorageForStateProviders,
this.storageService as BrowserLocalStorageService,
);
this.accountService = new AccountServiceImplementation(
@@ -338,11 +348,11 @@ export default class MainBackground {
);
this.activeUserStateProvider = new DefaultActiveUserStateProvider(
this.accountService,
this.memoryStorageService as BackgroundMemoryStorageService,
this.memoryStorageForStateProviders,
this.storageService as BrowserLocalStorageService,
);
this.derivedStateProvider = new BackgroundDerivedStateProvider(
this.memoryStorageService as BackgroundMemoryStorageService,
this.memoryStorageForStateProviders,
);
this.stateProvider = new DefaultStateProvider(
this.activeUserStateProvider,

View File

@@ -1,4 +1,5 @@
import { MemoryStorageService } from "@bitwarden/common/platform/services/memory-storage.service";
// eslint-disable-next-line import/no-restricted-paths -- Implementation for memory storage specifically for browser backgrounds
import { MemoryStorageService } from "@bitwarden/common/platform/state/storage/memory-storage.service";
import { BrowserApi } from "../browser/browser-api";
@@ -27,7 +28,7 @@ export class BackgroundMemoryStorageService extends MemoryStorageService {
// Initialize the new memory storage service with existing data
this.sendMessageTo(port, {
action: "initialization",
data: Array.from(this.store.keys()),
data: Array.from(Object.keys(this.store)),
});
});
this.updates$.subscribe((update) => {