1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 15:53:27 +00:00

Vault/pm-7580/resolve-cipher-update-race (#8806)

* Resolve updated values from updates

Uses the now returned updated values from cipher service to guarantee-return the updated cipher for CLI edits

* Use updated cipher for creation

* Use updated cipher for editing collections

* Await async methods

Cipher data more closely approximates server responses. TODO: this should really use actual response types
This commit is contained in:
Matt Gibson
2024-04-18 14:06:31 -04:00
committed by GitHub
parent d5f503a0d6
commit ce75f7b565
5 changed files with 73 additions and 50 deletions

View File

@@ -86,8 +86,7 @@ export class EditCommand {
cipherView = CipherExport.toView(req, cipherView);
const encCipher = await this.cipherService.encrypt(cipherView);
try {
await this.cipherService.updateWithServer(encCipher);
const updatedCipher = await this.cipherService.get(cipher.id);
const updatedCipher = await this.cipherService.updateWithServer(encCipher);
const decCipher = await updatedCipher.decrypt(
await this.cipherService.getKeyForCipherKeyDecryption(updatedCipher),
);
@@ -111,8 +110,7 @@ export class EditCommand {
cipher.collectionIds = req;
try {
await this.cipherService.saveCollectionsWithServer(cipher);
const updatedCipher = await this.cipherService.get(cipher.id);
const updatedCipher = await this.cipherService.saveCollectionsWithServer(cipher);
const decCipher = await updatedCipher.decrypt(
await this.cipherService.getKeyForCipherKeyDecryption(updatedCipher),
);

View File

@@ -80,8 +80,7 @@ export class CreateCommand {
private async createCipher(req: CipherExport) {
const cipher = await this.cipherService.encrypt(CipherExport.toView(req));
try {
await this.cipherService.createWithServer(cipher);
const newCipher = await this.cipherService.get(cipher.id);
const newCipher = await this.cipherService.createWithServer(cipher);
const decCipher = await newCipher.decrypt(
await this.cipherService.getKeyForCipherKeyDecryption(newCipher),
);
@@ -142,12 +141,11 @@ export class CreateCommand {
}
try {
await this.cipherService.saveAttachmentRawWithServer(
const updatedCipher = await this.cipherService.saveAttachmentRawWithServer(
cipher,
fileName,
new Uint8Array(fileBuf).buffer,
);
const updatedCipher = await this.cipherService.get(cipher.id);
const decCipher = await updatedCipher.decrypt(
await this.cipherService.getKeyForCipherKeyDecryption(updatedCipher),
);