From d50110f68579bb256a9970c15b1ffe986cd2f73a Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 25 Jan 2026 18:09:28 +0000 Subject: [PATCH] fix(storage): validate signer identity before unlocking storage Prevents storage unlock failures and security risks when switching profiles by verifying that the active signer's public key matches the target profile. This ensures users are prompted to switch accounts in their NIP-07 extension if a mismatch occurs. Fixes an issue where switching profiles caused the storage tab to break due to using the wrong decryption key. --- js/ui/profileModalController.js | 50 +++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/js/ui/profileModalController.js b/js/ui/profileModalController.js index 172f5807..c888d6cb 100644 --- a/js/ui/profileModalController.js +++ b/js/ui/profileModalController.js @@ -9095,33 +9095,53 @@ export class ProfileModalController { // ProfileModalController imports getActiveSigner. if (!signer) { - this.showError("No active signer found. Please login."); - return; + this.showError("No active signer found. Please login."); + return; + } + + if ( + signer.pubkey && + this.normalizeHexPubkey(signer.pubkey) !== pubkey + ) { + this.showError( + `Signer account (${signer.pubkey.slice( + 0, + 8, + )}...) does not match profile (${pubkey.slice( + 0, + 8, + )}...). Please switch accounts in your extension.`, + ); + return; } const storageService = this.services.storageService; if (!storageService) { - this.showError("Storage service unavailable."); - return; + this.showError("Storage service unavailable."); + return; } if (this.storageUnlockBtn) { - this.storageUnlockBtn.disabled = true; - this.storageUnlockBtn.textContent = "Unlocking..."; + this.storageUnlockBtn.disabled = true; + this.storageUnlockBtn.textContent = "Unlocking..."; } try { - await storageService.unlock(pubkey, { signer }); - this.showSuccess("Storage unlocked."); - this.populateStoragePane(); + await storageService.unlock(pubkey, { signer }); + this.showSuccess("Storage unlocked."); + this.populateStoragePane(); } catch (error) { - devLogger.error("Failed to unlock storage:", error); - this.showError("Failed to unlock storage. Ensure your signer supports NIP-04/44."); + devLogger.error("Failed to unlock storage:", error); + const message = + error && typeof error.message === "string" + ? error.message + : "Failed to unlock storage. Ensure your signer supports NIP-04/44."; + this.showError(message); } finally { - if (this.storageUnlockBtn) { - this.storageUnlockBtn.disabled = false; - this.storageUnlockBtn.textContent = "Unlock Storage"; - } + if (this.storageUnlockBtn) { + this.storageUnlockBtn.disabled = false; + this.storageUnlockBtn.textContent = "Unlock Storage"; + } } }