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

[PM-5468] Ensure prototypes available on memory stored objects (#7399)

* Hide account switcher in addEdit generator

* Handle AddEditCipher deserialization

* Opaque types are not serializable

* Better handle jsonification of login uris

* Ensure we don't overwrite original with clone

* Ensure cipherView prototype is always restored if it exists
This commit is contained in:
Matt Gibson
2024-01-02 10:46:45 -05:00
committed by GitHub
parent 90b794c74d
commit a682f2a0ef
9 changed files with 51 additions and 17 deletions

View File

@@ -27,6 +27,7 @@ import { CollectionData } from "../../../vault/models/data/collection.data";
import { FolderData } from "../../../vault/models/data/folder.data";
import { CipherView } from "../../../vault/models/view/cipher.view";
import { CollectionView } from "../../../vault/models/view/collection.view";
import { AddEditCipherInfo } from "../../../vault/types/add-edit-cipher-info";
import { KdfType } from "../../enums";
import { Utils } from "../../misc/utils";
import { ServerConfigData } from "../../models/data/server-config.data";
@@ -101,10 +102,23 @@ export class AccountData {
GeneratedPasswordHistory[],
GeneratedPasswordHistory[]
> = new EncryptionPair<GeneratedPasswordHistory[], GeneratedPasswordHistory[]>();
addEditCipherInfo?: any;
addEditCipherInfo?: AddEditCipherInfo;
eventCollection?: EventData[];
organizations?: { [id: string]: OrganizationData };
providers?: { [id: string]: ProviderData };
static fromJSON(obj: DeepJsonify<AccountData>): AccountData {
if (obj == null) {
return null;
}
return Object.assign(new AccountData(), obj, {
addEditCipherInfo: {
cipher: CipherView.fromJSON(obj?.addEditCipherInfo?.cipher),
collectionIds: obj?.addEditCipherInfo?.collectionIds,
},
});
}
}
export class AccountKeys {
@@ -152,7 +166,7 @@ export class AccountKeys {
if (obj == null) {
return null;
}
return Object.assign(new AccountKeys(), {
return Object.assign(new AccountKeys(), obj, {
userKey: SymmetricCryptoKey.fromJSON(obj?.userKey),
masterKey: SymmetricCryptoKey.fromJSON(obj?.masterKey),
deviceKey: obj?.deviceKey,
@@ -451,6 +465,7 @@ export class Account {
return Object.assign(new Account({}), json, {
keys: AccountKeys.fromJSON(json?.keys),
data: AccountData.fromJSON(json?.data),
profile: AccountProfile.fromJSON(json?.profile),
settings: AccountSettings.fromJSON(json?.settings),
tokens: AccountTokens.fromJSON(json?.tokens),

View File

@@ -40,7 +40,7 @@ export class EncString implements Encrypted {
}
toJSON() {
return this.encryptedString;
return this.encryptedString as string;
}
static fromJSON(obj: Jsonify<EncString>): EncString {

View File

@@ -31,8 +31,8 @@ export class MemoryStorageService extends AbstractMemoryStorageService {
}
// TODO: Remove once foreground/background contexts are separated in browser
// Needed to ensure ownership of all memory by the context running the storage service
obj = structuredClone(obj);
this.store.set(key, obj);
const toStore = structuredClone(obj);
this.store.set(key, toStore);
this.updatesSubject.next({ key, updateType: "save" });
return Promise.resolve();
}

View File

@@ -280,9 +280,20 @@ export class StateService<
}
async getAddEditCipherInfo(options?: StorageOptions): Promise<AddEditCipherInfo> {
return (
await this.getAccount(this.reconcileOptions(options, await this.defaultInMemoryOptions()))
)?.data?.addEditCipherInfo;
const account = await this.getAccount(
this.reconcileOptions(options, await this.defaultInMemoryOptions()),
);
// ensure prototype on cipher
const raw = account?.data?.addEditCipherInfo;
return raw == null
? null
: {
cipher:
raw?.cipher.toJSON != null
? raw.cipher
: CipherView.fromJSON(raw?.cipher as Jsonify<CipherView>),
collectionIds: raw?.collectionIds,
};
}
async setAddEditCipherInfo(value: AddEditCipherInfo, options?: StorageOptions): Promise<void> {