Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Cleanup in-memory state after lock or logout (#2159)

Leendert de Borst3d2777cdecd8
diff --git a/apps/browser-extension/src/entrypoints/background/SavePromptStateHandler.ts b/apps/browser-extension/src/entrypoints/background/SavePromptStateHandler.ts
index 3b2d169f5..6955456e1 100644
--- a/apps/browser-extension/src/entrypoints/background/SavePromptStateHandler.ts
+++ b/apps/browser-extension/src/entrypoints/background/SavePromptStateHandler.ts
@@ -206,3 +206,20 @@ export function handleClearLastAutofilled(
return { success: true };
}
+/**
+ * Clear the save prompt and last-autofilled state for every tab. Called on vault lock and logout.
+ */
+export function clearAllSavePromptState(): void {
+ for (const timer of stateExpiryTimers.values()) {
+ clearTimeout(timer);
+ }
+
+ for (const timer of autofillExpiryTimers.values()) {
+ clearTimeout(timer);
+ }
+
+ savePromptStateByTab.clear();
+ stateExpiryTimers.clear();
+ lastAutofilledByTab.clear();
+ autofillExpiryTimers.clear();
+}
diff --git a/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts b/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts
index 18feb39e2..e4c066bf3 100644
--- a/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts
+++ b/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts
@@ -1,6 +1,9 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { storage } from 'wxt/utils/storage';
+import { clearAllSavePromptState } from '@/entrypoints/background/SavePromptStateHandler';
+import { handleClearTwoFactorState } from '@/entrypoints/background/TwoFactorStateHandler';
+
import { base64ToBytes } from '@/utils/Base64';
import { AUTH_STORAGE_KEYS, dirtyScopeStorageKey, SESSION_STORAGE_KEYS, StorageKeys, vaultDataStorageKeys, VAULT_LOCK_STORAGE_KEYS } from '@/utils/constants/storageKeys';
import { TRASH_RETENTION_DAYS } from '@/utils/constants/vault';
@@ -62,7 +65,7 @@ import { t } from '@/i18n/StandaloneI18n';
* - New vault from remote (login, sync): Clear cache by setting both to null, WITHOUT closing — an in-flight
* flow (e.g. a push holding the client across an HTTP await, or persistLocalVaultMutation re-adopting the
* client it just stored) may legitimately still use the detached instance.
- * - Lock/logout/clear vault: cleanupCachedSqliteClient().
+ * - Lock/logout/clear vault: clearInMemoryVaultState().
*/
let cachedSqliteClient: SqliteClient | null = null;
let cachedVaultBlob: string | null = null;
@@ -74,6 +77,17 @@ function cleanupCachedSqliteClient(): void {
cachedSqliteClient?.close();
cachedSqliteClient = null;
cachedVaultBlob = null;
+ // The pre-push canonicalize result holds plaintext rows, plaintext blob bytes and unwrapped shared-manifest VEKs, so it dies with the vault it came from.
+ invalidateCanonicalizeCache();
+}
+
+/**
+ * Drop all plaintext state the background script holds in memory, on lock, logout and vault clear.
+ */
+function clearInMemoryVaultState(): void {
+ cleanupCachedSqliteClient();
+ clearAllSavePromptState();
+ handleClearTwoFactorState();
}
/**
@@ -380,7 +394,7 @@ export async function handleGetVault(
*/
export async function handleLockVault(): Promise<messageBoolResponse> {
await storage.removeItems([...VAULT_LOCK_STORAGE_KEYS]);
- cleanupCachedSqliteClient();
+ clearInMemoryVaultState();
return { success: true };
}
@@ -402,7 +416,7 @@ export async function handleClearSession(): Promise<messageBoolResponse> {
await LocalPreferencesService.resetPasswordUnlockFailedAttempts();
// Cleanup cached sqlite client
- cleanupCachedSqliteClient();
+ clearInMemoryVaultState();
return { success: true };
}
@@ -422,7 +436,7 @@ export async function handleClearVaultData(): Promise<messageBoolResponse> {
await LocalPreferencesService.clearAll();
// Free the decrypted vault held in service-worker memory alongside the persisted data it came from.
- cleanupCachedSqliteClient();
+ clearInMemoryVaultState();
return { success: true };
}
diff --git a/apps/browser-extension/src/utils/constants/storageKeys.ts b/apps/browser-extension/src/utils/constants/storageKeys.ts
index 03c1928ab..0198e6700 100644
--- a/apps/browser-extension/src/utils/constants/storageKeys.ts
+++ b/apps/browser-extension/src/utils/constants/storageKeys.ts
@@ -221,6 +221,7 @@ export const VAULT_LOCK_STORAGE_KEYS: readonly StorageKey[] = [
StorageKeys.ENCRYPTION_KEY,
StorageKeys.ACCOUNT_PRIVATE_KEY,
StorageKeys.PERSISTED_FORM_VALUES,
+ StorageKeys.RECENTLY_SELECTED_ITEM,
];
/** Session keys cleared on logout: everything from a lock, plus the popup navigation state. */