Skip to content

Commit

Permalink
Fix key rotation being broken due to org ciphers being included (#10140)
Browse files Browse the repository at this point in the history
  • Loading branch information
quexten authored Jul 17, 2024
1 parent e27d698 commit fd93c76
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions libs/common/src/vault/services/cipher.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,10 @@ describe("Cipher Service", () => {

const cipher1 = new CipherView(cipherObj);
cipher1.id = "Cipher 1";
cipher1.organizationId = null;
const cipher2 = new CipherView(cipherObj);
cipher2.id = "Cipher 2";
cipher2.organizationId = null;

decryptedCiphers = new BehaviorSubject({
Cipher1: cipher1,
Expand Down
9 changes: 7 additions & 2 deletions libs/common/src/vault/services/cipher.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1184,11 +1184,16 @@ export class CipherService implements CipherServiceAbstraction {
let encryptedCiphers: CipherWithIdRequest[] = [];

const ciphers = await this.getAllDecrypted();
if (!ciphers || ciphers.length === 0) {
if (!ciphers) {
return encryptedCiphers;
}

const userCiphers = ciphers.filter((c) => c.organizationId == null);
if (userCiphers.length === 0) {
return encryptedCiphers;
}
encryptedCiphers = await Promise.all(
ciphers.map(async (cipher) => {
userCiphers.map(async (cipher) => {
const encryptedCipher = await this.encrypt(cipher, newUserKey, originalUserKey);
return new CipherWithIdRequest(encryptedCipher);
}),
Expand Down

0 comments on commit fd93c76

Please sign in to comment.