handle encryption when adding accounts to multisig wallets with mixed seed and watch-only keystores
What changed, and why it matters
This commit fixes a bug in Sparrow Wallet that occurred when adding accounts to certain multi-signature wallets. In wallets that mix 'seed' keystores (which hold private keys) with 'watch-only' keystores (which do not), newly added child accounts were being left unencrypted after the operation. The patch ensures each new child wallet is encrypted and that the parent wallet is re-encrypted afterward, preventing private key material from remaining exposed in memory longer than intended.
Treat this as a security fix and include it in the next release. Users who added accounts to mixed-source multisig wallets before this patch should be advised to close and reopen Sparrow to clear any in-memory unencrypted state, and to avoid leaving such wallets open on shared or untrusted machines. No immediate on-chain funds-at-risk is evident, but the fix reduces exposure of private key material.
Security signals we found
Missing re-encryption of sensitive key material after wallet operation
Private key exposure window in mixed-seed/watch-only multisig wallets
finally block added to guarantee encryption and key clearing
child wallets now explicitly encrypted after creation
Evidence from the diff
SettingsController.addAccounts() decrypts masterWallet with the wallet password key when adding standard accounts. For multisig wallets containing any keystore whose source is not SW_SEED (i.e., hardware-wallet or watch-only keystores), the code previously created child wallets while the master wallet was decrypted but never re-encrypted the children or the master wallet before the method returned. The patch wraps child creation in a try/finally: each childWallet is encrypted with the same key, and masterWallet.encrypt(key) plus key.clear() are guaranteed to run. This closes a window where private key bytes could remain unencrypted in Wallet/Keystore objects.
Changed components
src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.javaWallet.addChildWallet() / Wallet.encrypt() / Wallet.decrypt()Keystore encryption state for multisig wallets with mixed keystore sourcesInspect captured patch +9 / −3
### src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java
@@ -701,9 +701,15 @@ private void addAccounts(Wallet masterWallet, List<StandardAccount> standardAcco
masterWallet.decrypt(key);
if(masterWallet.getKeystores().stream().anyMatch(ks -> ks.getSource() != KeystoreSource.SW_SEED)) {
- for(StandardAccount standardAccount : standardAccounts) {
- Wallet childWallet = masterWallet.addChildWallet(standardAccount);
- EventManager.get().post(new ChildWalletsAddedEvent(getWalletForm().getStorage(), masterWallet, childWallet));
+ try {
+ for(StandardAccount standardAccount : standardAccounts) {
+ Wallet childWallet = masterWallet.addChildWallet(standardAccount);
+ childWallet.encrypt(key);
+ EventManager.get().post(new ChildWalletsAddedEvent(getWalletForm().getStorage(), masterWallet, childWallet));
+ }
+ } finally {
+ masterWallet.encrypt(key);
+ key.clear();
}
} else if(discoverAccounts) {
ElectrumServer.AccountDiscoveryService accountDiscoveryService = new ElectrumServer.AccountDiscoveryService(masterWallet, standardAccounts);Why this scored 56/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.