Fix wallet address, email credential and invoice policy handling (#7768)
What changed, and why it matters
This commit fixes several bugs in BTCPay Server. The most notable changes are: (1) email SMTP passwords are now only reused when the mail server hasn't changed, preventing a stored password from being sent to a different server; (2) anonymous BitPay API users can no longer override a store's invoice confirmation-speed policy; and (3) wallet change events are now published when payment methods are added or removed, and cached receive addresses are cleared when a wallet's derivation scheme changes, which helps prevent stale or wrong addresses from being handed out. The commit is described by the vendor as a bug-fix, not a security patch, and no CVE or independent researcher attribution is present in the materials.
Treat this as a routine bug-fix update with security-hardening side effects. Review whether the email password and invoice speed-policy changes warrant a security advisory; the commit message does not frame them as security issues, but the behaviors fixed could have had security implications. No immediate emergency response is indicated by the diff alone.
Security signals we found
Email password reuse across different SMTP servers is prevented
Anonymous BitPay API users can no longer override store invoice speed policy
Wallet change events are now emitted on payment method add/remove/config update
Cached receive addresses are invalidated when derivation scheme changes
WalletId in wallet-change events now consistently uses network.CryptoCode instead of user-supplied vm.CryptoCode
Evidence from the diff
The patch touches three areas. First, EmailSettings.GetPasswordFor(server) now returns the saved password only when the configured server matches the incoming server (ordinal-ignore-case). Controllers for server, store, and UI email settings were updated to pass the request’s server into this helper, so a password is not silently carried over to a new SMTP server. Second, BitpayInvoiceController.SpeedPolicy now ignores invoice.TransactionSpeed for anonymous (unauthenticated) BitPay API requests, falling back to the store’s policy; authenticated requests still parse the supplied speed. Third, WalletChangedEvent is published in GreenfieldStorePaymentMethodsController on removal and config update, in UIMultisigWalletsController after multisig setup, and UIStoreOnChainWalletsController now uses network.CryptoCode consistently for the event’s WalletId. WalletReceiveService.GetOrGenerate now checks derivationScheme before reusing a cached address, removes stale entries when the wallet/derivation is missing or changed, and uses TryGetValue. Swagger text for the email password field was updated to clarify the preservation behavior.
Changed components
Greenfield server email settings APIGreenfield store email settings APIUI email settings controller baseBitPay invoice controllerGreenfield store payment methods APIMultisig wallet setup UIOn-chain wallet settings/deletion UIWallet receive address serviceEmail settings modelInspect captured patch +39 / −22
### BTCPayServer/Controllers/GreenField/GreenfieldServerEmailController.cs
@@ -60,7 +60,7 @@ public async Task<IActionResult> ServerEmailSettings(ServerEmailSettingsData req
}
var settings = await _emailSenderFactory.GetSettings();
- settings = EmailSettings.FromData(request, settings?.Password);
+ settings = EmailSettings.FromData(request, settings?.GetPasswordFor(request.Server));
// important to save as EmailSettings otherwise it won't be able to be fetched
await _settingsRepository.UpdateSetting(settings);
### BTCPayServer/Controllers/GreenField/GreenfieldStoreEmailController.cs
@@ -67,7 +67,7 @@ public async Task<IActionResult> UpdateStoreEmailSettings(string storeId, EmailS
var store = HttpContext.GetStoreData();
var blob = store.GetStoreBlob();
- var settings = EmailSettings.FromData(request, blob.EmailSettings?.Password);
+ var settings = EmailSettings.FromData(request, blob.EmailSettings?.GetPasswordFor(request.Server));
blob.EmailSettings = settings;
if (store.SetStoreBlob(blob))
await _storeRepository.UpdateStore(store);
### BTCPayServer/Controllers/GreenField/GreenfieldStorePaymentMethodsController.cs
@@ -5,6 +5,7 @@
using BTCPayServer.Client;
using BTCPayServer.Client.Models;
using BTCPayServer.Data;
+using BTCPayServer.Events;
using BTCPayServer.Services.Invoices;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
@@ -14,6 +15,7 @@
using StoreData = BTCPayServer.Data.StoreData;
using BTCPayServer.ModelBinders;
using BTCPayServer.Payments;
+using BTCPayServer.Payments.Bitcoin;
using BTCPayServer.Services.Stores;
using System;
@@ -25,6 +27,7 @@ namespace BTCPayServer.Controllers.Greenfield
public class GreenfieldStorePaymentMethodsController(
PaymentMethodHandlerDictionary handlers,
StoreRepository storeRepository,
+ EventAggregator eventAggregator,
IAuthorizationService authorizationService)
: ControllerBase
{
@@ -55,11 +58,12 @@ public async Task<IActionResult> RemoveStorePaymentMethod(
[ModelBinder(typeof(PaymentMethodIdModelBinder))]
PaymentMethodId paymentMethodId)
{
- AssertHasHandler(paymentMethodId);
+ var handler = AssertHasHandler(paymentMethodId);
if (Store.GetPaymentMethodConfig(paymentMethodId) is null)
return Ok();
Store.SetPaymentMethodConfig(paymentMethodId, null);
await storeRepository.UpdateStore(Store);
+ PublishWalletChanged(handler);
return Ok();
}
@@ -111,9 +115,17 @@ public async Task<IActionResult> UpdateStorePaymentMethod(
}
await storeRepository.UpdateStore(Store);
+ if (request?.Config is not null)
+ PublishWalletChanged(handler);
return await GetStorePaymentMethod(storeId, paymentMethodId, request?.Config is not null);
}
+ private void PublishWalletChanged(IPaymentMethodHandler handler)
+ {
+ if (handler is BitcoinLikePaymentHandler { Network: var network })
+ eventAggregator.Publish(new WalletChangedEvent { WalletId = new WalletId(Store.Id, network.CryptoCode) });
+ }
+
private IPaymentMethodHandler AssertHasHandler(PaymentMethodId paymentMethodId)
{
if (!handlers.TryGetValue(paymentMethodId, out var handler))
### BTCPayServer/Plugins/Bitpay/Controllers/BitpayInvoiceController.cs
@@ -187,7 +187,9 @@ redirectUri.Scheme is not ("http" or "https")))
entity.RedirectURLTemplate = invoice.RedirectURL ?? store.StoreWebsite;
entity.RedirectAutomatically =
invoice.RedirectAutomatically.GetValueOrDefault(storeBlob.RedirectAutomatically);
- entity.SpeedPolicy = ParseSpeedPolicy(invoice.TransactionSpeed, store.SpeedPolicy);
+ entity.SpeedPolicy = User.Identity?.AuthenticationType == Security.BitpayAuthenticationTypes.Anonymous
+ ? store.SpeedPolicy
+ : ParseSpeedPolicy(invoice.TransactionSpeed, store.SpeedPolicy);
IPaymentFilter excludeFilter = null;
if (invoice.PaymentCurrencies?.Any() is true)
### BTCPayServer/Plugins/Emails/Controllers/UIEmailControllerBase.cs
@@ -47,7 +47,7 @@ protected async Task<IActionResult> EmailSettingsCore(Context ctx, EmailsViewMod
if (model.PasswordSet)
{
var settings = await GetEmailSettings(ctx);
- model.Settings.Password = settings.Password;
+ model.Settings.Password = settings.GetPasswordFor(model.Settings.Server);
}
model.Settings.Validate("Settings.", ModelState);
@@ -113,8 +113,8 @@ protected async Task<IActionResult> EmailSettingsCore(Context ctx, EmailsViewMod
}
var oldSettings = await GetEmailSettings(ctx);
- if (!string.IsNullOrEmpty(oldSettings.Password))
- model.Settings.Password = oldSettings.Password;
+ if (oldSettings.GetPasswordFor(model.Settings.Server) is { Length: > 0 } password)
+ model.Settings.Password = password;
await SaveEmailSettings(ctx, model.Settings, model);
TempData[WellKnownTempData.SuccessMessage] = StringLocalizer["Email settings saved"].Value;
### BTCPayServer/Plugins/Emails/Services/EmailSettings.cs
@@ -29,6 +29,9 @@ public bool EnabledCertificateCheck
// Conversion functions for mapping to and from the client EmailSettingsData model
#nullable enable
+ public string? GetPasswordFor(string? server)
+ => string.Equals(Server, server, System.StringComparison.OrdinalIgnoreCase) ? Password : null;
+
public static EmailSettings FromData(EmailSettingsData data, string? existingPassword)
=> new()
{
### BTCPayServer/Plugins/Multisig/Controllers/UIMultisigWalletsController.cs
@@ -8,6 +8,7 @@
using BTCPayServer.Abstractions.Extensions;
using BTCPayServer.Client;
using BTCPayServer.Data;
+using BTCPayServer.Events;
using BTCPayServer.Payments;
using BTCPayServer.Plugins.Multisig.Models;
using BTCPayServer.Plugins.Multisig.Services;
@@ -36,6 +37,7 @@ public class UIMultisigWalletsController(
MultisigNotificationService multisigNotificationService,
CallbackGenerator callbackGenerator,
PaymentMethodHandlerDictionary paymentMethodHandlerDictionary,
+ EventAggregator eventAggregator,
IStringLocalizer stringLocalizer) : Controller
{
public IStringLocalizer StringLocalizer { get; } = stringLocalizer;
@@ -212,6 +214,7 @@ private async Task<IActionResult> ConfirmMultisigSetup(MultisigSetupViewModel vm
storeBlob.SetExcluded(paymentMethodId, false);
store.SetStoreBlob(storeBlob);
await storeRepository.UpdateStore(store);
+ eventAggregator.Publish(new WalletChangedEvent { WalletId = new WalletId(store.Id, network.CryptoCode) });
var finalizedPendingSetting = await multisigService.GetPendingMultisigSetupContext(vm.StoreId, vm.MultisigRequestId);
if (finalizedPendingSetting is not null)
### BTCPayServer/Plugins/Wallets/Controllers/UIStoreOnChainWalletsController.cs
@@ -604,7 +604,7 @@ public async Task<IActionResult> UpdateWalletSettings(
var successMessage = "Wallet settings successfully updated.";
if (enabledChanged)
{
- eventAggregator.Publish(new WalletChangedEvent { WalletId = new WalletId(vm.StoreId, vm.CryptoCode) });
+ eventAggregator.Publish(new WalletChangedEvent { WalletId = new WalletId(vm.StoreId, network.CryptoCode) });
successMessage += $" {vm.CryptoCode} on-chain payments are now {(vm.Enabled ? "enabled" : "disabled")} for this store.";
}
@@ -739,7 +739,7 @@ public async Task<IActionResult> ConfirmDeleteWallet([FromRoute] string storeId,
store.SetPaymentMethodConfig(PaymentTypes.CHAIN.GetPaymentMethodId(network.CryptoCode), null);
await storeRepo.UpdateStore(store);
- eventAggregator.Publish(new WalletChangedEvent { WalletId = new WalletId(storeId, cryptoCode) });
+ eventAggregator.Publish(new WalletChangedEvent { WalletId = new WalletId(store.Id, network.CryptoCode) });
TempData[WellKnownTempData.SuccessMessage] =
$"On-Chain payment for {network.CryptoCode} has been removed.";
### BTCPayServer/Services/Wallets/WalletReceiveService.cs
@@ -62,20 +62,22 @@ public async Task<string> UnReserveAddress(WalletId walletId)
public async Task<KeyPathInformation> GetOrGenerate(WalletId walletId, bool forceGenerate = false)
{
- var existing = Get(walletId);
- if (existing != null && !forceGenerate)
- {
- return existing;
- }
-
var wallet = _btcPayWalletProvider.GetWallet(walletId.CryptoCode);
var store = await _storeRepository.FindStore(walletId.StoreId);
var derivationScheme = store?.GetDerivationSchemeSettings(_handlers, walletId.CryptoCode);
if (wallet is null || derivationScheme is null)
{
+ Remove(walletId);
return null;
}
+ var existing = Get(walletId);
+ if (existing != null && !forceGenerate && existing.DerivationStrategy == derivationScheme.AccountDerivation)
+ {
+ return existing;
+ }
+
+ Remove(walletId);
var reserve = (await wallet.ReserveAddressAsync(walletId.StoreId, derivationScheme.AccountDerivation, "receive"));
Set(walletId, reserve);
return reserve;
@@ -88,12 +90,7 @@ public void Remove(WalletId walletId)
public KeyPathInformation Get(WalletId walletId)
{
- if (_walletReceiveState.ContainsKey(walletId))
- {
- return _walletReceiveState[walletId];
- }
-
- return null;
+ return _walletReceiveState.TryGetValue(walletId, out var existing) ? existing : null;
}
private void Set(WalletId walletId, KeyPathInformation information)
### BTCPayServer/wwwroot/swagger/v1/swagger.template.stores-email.json
@@ -174,7 +174,7 @@
"properties": {
"password": {
"type": "string",
- "description": "SMTP password. Keep null or empty to not update it.",
+ "description": "SMTP password. Null or empty preserves the saved password only when login is provided and server is unchanged.",
"nullable": true,
"example": "MyS3cr3t"
}Why this scored 57/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.