From 9544da28c7000775439951b80de8847f5af62c4b Mon Sep 17 00:00:00 2001 From: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com> Date: Tue, 19 Dec 2023 17:04:25 -0500 Subject: [PATCH] PM-5304 - Sync Service - setForceSetPasswordReasonIfNeeded(...) - Add bandaid to early return if state gets corrupted with undefined acctDecryptionOpts so that the sync won't error and prevent users from accessing their data added on another device. (#7265) --- libs/common/src/vault/services/sync/sync.service.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libs/common/src/vault/services/sync/sync.service.ts b/libs/common/src/vault/services/sync/sync.service.ts index 93d88ac0fbe..9195e39311b 100644 --- a/libs/common/src/vault/services/sync/sync.service.ts +++ b/libs/common/src/vault/services/sync/sync.service.ts @@ -353,6 +353,18 @@ export class SyncService implements SyncServiceAbstraction { const acctDecryptionOpts: AccountDecryptionOptions = await this.stateService.getAccountDecryptionOptions(); + // Account decryption options should never be null or undefined b/c it is always initialized + // during the processing of the ID token response, but there might be a state issue + // where it is being overwritten with undefined affecting browser extension + FireFox users. + // TODO: Consider removing this once we figure out the root cause of the state issue or after the state provider refactor. + if (acctDecryptionOpts === null || acctDecryptionOpts === undefined) { + this.logService.error("Sync: Account decryption options are null or undefined."); + // Early return as a bandaid to allow the rest of the sync to continue so users can access + // their data that they might have added from another device. + // Otherwise, trying to access properties on undefined below will throw an error. + return; + } + // Even though TDE users should only be in a single org (per single org policy), check // through all orgs for the manageResetPassword permission. If they have it in any org, // they should be forced to set a password.