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:
@@ -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),
|
||||
|
||||
@@ -40,7 +40,7 @@ export class EncString implements Encrypted {
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return this.encryptedString;
|
||||
return this.encryptedString as string;
|
||||
}
|
||||
|
||||
static fromJSON(obj: Jsonify<EncString>): EncString {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user