1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 16:23:44 +00:00

Handle string, enc string (split is not a function) errors during browser extension deserialization (#15586)

This commit is contained in:
SmithThe4th
2025-07-15 17:21:15 -04:00
committed by GitHub
parent 72d6eb3d99
commit 6cb6316afd

View File

@@ -45,7 +45,17 @@ export class AttachmentView implements View {
static fromJSON(obj: Partial<Jsonify<AttachmentView>>): AttachmentView {
const key = obj.key == null ? null : SymmetricCryptoKey.fromJSON(obj.key);
const encryptedKey = obj.encryptedKey == null ? undefined : new EncString(obj.encryptedKey);
let encryptedKey: EncString | undefined;
if (obj.encryptedKey != null) {
if (typeof obj.encryptedKey === "string") {
// If the key is a string, we need to parse it as EncString
encryptedKey = EncString.fromJSON(obj.encryptedKey);
} else if ((obj.encryptedKey as any) instanceof EncString) {
// If the key is already an EncString instance, we can use it directly
encryptedKey = obj.encryptedKey;
}
}
return Object.assign(new AttachmentView(), obj, { key: key, encryptedKey: encryptedKey });
}
@@ -80,8 +90,8 @@ export class AttachmentView implements View {
view.sizeName = obj.sizeName ?? null;
view.fileName = obj.fileName ?? null;
// TODO: PM-23005 - Temporary field, should be removed when encrypted migration is complete
view.key = obj.key ? SymmetricCryptoKey.fromString(obj.decryptedKey) : null;
view.encryptedKey = new EncString(obj.key);
view.key = obj.decryptedKey ? SymmetricCryptoKey.fromString(obj.decryptedKey) : null;
view.encryptedKey = obj.key ? new EncString(obj.key) : undefined;
return view;
}