Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Tweak vault lock logic (#1404)
Leendert de Borst174fe630d5f3
diff --git a/apps/browser-extension/src/entrypoints/background.ts b/apps/browser-extension/src/entrypoints/background.tsindex 3e76006ff..4e81dc669 100644--- a/apps/browser-extension/src/entrypoints/background.ts+++ b/apps/browser-extension/src/entrypoints/background.ts@@ -9,7 +9,7 @@ import { handleClipboardCopied, handleCancelClipboardClear, handleGetClipboardClimport { setupContextMenus } from '@/entrypoints/background/ContextMenu';import { handleGetWebAuthnSettings, handleWebAuthnCreate, handleWebAuthnGet, handlePasskeyPopupResponse, handleGetRequestData } from '@/entrypoints/background/PasskeyHandler';import { handleOpenPopup, handlePopupWithCredential, handleOpenPopupCreateCredential, handleToggleContextMenu } from '@/entrypoints/background/PopupMessageHandler';-import { handleCheckAuthStatus, handleClearPersistedFormValues, handleClearVault, handleCreateIdentity, handleGetCredentials, handleGetDefaultEmailDomain, handleGetDefaultIdentitySettings, handleGetEncryptionKey, handleGetEncryptionKeyDerivationParams, handleGetPasswordSettings, handleGetPersistedFormValues, handleGetVault, handlePersistFormValues, handleStoreEncryptionKey, handleStoreEncryptionKeyDerivationParams, handleStoreVault, handleSyncVault, handleUploadVault, handleGetOfflineMode, handleSetOfflineMode, handleGetEncryptedVault, handleStoreEncryptedVault, handleGetHasPendingSync, handleSetHasPendingSync } from '@/entrypoints/background/VaultMessageHandler';+import { handleCheckAuthStatus, handleClearPersistedFormValues, handleClearVault, handleLockVault, handleCreateIdentity, handleGetCredentials, handleGetDefaultEmailDomain, handleGetDefaultIdentitySettings, handleGetEncryptionKey, handleGetEncryptionKeyDerivationParams, handleGetPasswordSettings, handleGetPersistedFormValues, handleGetVault, handlePersistFormValues, handleStoreEncryptionKey, handleStoreEncryptionKeyDerivationParams, handleStoreVault, handleSyncVault, handleUploadVault, handleGetOfflineMode, handleSetOfflineMode, handleGetEncryptedVault, handleStoreEncryptedVault, handleGetHasPendingSync, handleSetHasPendingSync } from '@/entrypoints/background/VaultMessageHandler';import { GLOBAL_CONTEXT_MENU_ENABLED_KEY } from '@/utils/Constants';import { EncryptionKeyDerivationParams } from "@/utils/dist/shared/models/metadata";@@ -40,6 +40,7 @@ export default defineBackground({onMessage('CREATE_IDENTITY', ({ data }) => handleCreateIdentity(data));onMessage('UPLOAD_VAULT', ({ data }) => handleUploadVault(data));onMessage('SYNC_VAULT', () => handleSyncVault());+ onMessage('LOCK_VAULT', () => handleLockVault());onMessage('CLEAR_VAULT', () => handleClearVault());// Offline mode management messagesdiff --git a/apps/browser-extension/src/entrypoints/background/AutolockTimeoutHandler.ts b/apps/browser-extension/src/entrypoints/background/AutolockTimeoutHandler.tsindex 1e854f25b..4b5c67241 100644--- a/apps/browser-extension/src/entrypoints/background/AutolockTimeoutHandler.ts+++ b/apps/browser-extension/src/entrypoints/background/AutolockTimeoutHandler.ts@@ -1,6 +1,6 @@import { storage } from 'wxt/utils/storage';-import { handleClearVault } from '@/entrypoints/background/VaultMessageHandler';+import { handleLockVault } from '@/entrypoints/background/VaultMessageHandler';import { AUTO_LOCK_TIMEOUT_KEY } from '@/utils/Constants';@@ -58,8 +58,7 @@ async function resetAutoLockTimer(): Promise<void> {// Set new timerautoLockTimer = setTimeout(async () => {try {- // Lock the vault using the existing handler- handleClearVault();+ handleLockVault();console.info('[AUTO_LOCK] Vault locked due to inactivity');autoLockTimer = null;@@ -99,8 +98,8 @@ async function extendAutoLockTimer(): Promise<void> {// Set new timerautoLockTimer = setTimeout(async () => {try {- // Lock the vault using the existing handler- handleClearVault();+ // Lock the vault (preserves local data for offline unlock)+ handleLockVault();console.info('[AUTO_LOCK] Vault locked due to inactivity');autoLockTimer = null;diff --git a/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts b/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.tsindex f92e1d1f8..47ddb1fe3 100644--- a/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts+++ b/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts@@ -243,10 +243,24 @@ export async function handleGetVault(}/**- * Clear the vault from browser storage (both local: and session:).+ * Lock the vault by clearing only session data.+ * This preserves local vault data so user can unlock again without server.*/-export function handleClearVault(-) : messageBoolResponse {+export function handleLockVault(): messageBoolResponse {+ // Clear session-only data (locks the vault)+ storage.removeItems([+ 'session:encryptionKey',+ 'session:persistedFormValues',+ ]);++ return { success: true };+}++/**+ * Clear the vault completely from browser storage (both local: and session:).+ * This is used for full logout - removes all vault data.+ */+export function handleClearVault(): messageBoolResponse {// Clear persistent vault data from local: storagestorage.removeItems(['local:encryptedVault',@@ -262,10 +276,7 @@ export function handleClearVault(// Clear session-only datastorage.removeItems(['session:encryptionKey',- // TODO: the derivedKey clear can be removed some period of time after 0.22.0 is released.- 'session:derivedKey',- // TODO: the session encryptionKeyDerivationParams clear can be removed after users have migrated to local: storage.- 'session:encryptionKeyDerivationParams'+ 'session:persistedFormValues',]);return { success: true };diff --git a/apps/browser-extension/src/entrypoints/popup/pages/settings/Settings.tsx b/apps/browser-extension/src/entrypoints/popup/pages/settings/Settings.tsxindex bc83c405d..5d00695bc 100644--- a/apps/browser-extension/src/entrypoints/popup/pages/settings/Settings.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/settings/Settings.tsx@@ -119,8 +119,7 @@ const Settings: React.FC = () => {* Handle lock vault.*/const handleLock = async () : Promise<void> => {- // Clear the vault which will lock it and require user to login again- await sendMessage('CLEAR_VAULT', {}, 'background');+ await sendMessage('LOCK_VAULT', {}, 'background');// Navigate to unlock pagenavigate('/unlock');