Simplify payout destination handling
What changed, and why it matters
This commit simplifies how BTCPay Server builds Bitcoin payment links (BIP21 URLs) when processing payouts. Previously, the code handled two separate cases: one for raw Bitcoin addresses and one for BIP21 URLs (like 'bitcoin:...' links). Now it treats both through a common interface. The change removes special handling that modified existing BIP21 URLs in place, instead always generating a fresh BIP21 URL from the address. This is a code cleanup/refactoring change. There is no direct evidence in the commit that this fixes a security vulnerability, but it removes a code path that could potentially mishandle externally supplied BIP21 URLs.
Review whether the removed UriClaimDestination behavior was intentional for preserving merchant-supplied BIP21 parameters (e.g., labels, messages). If so, this change may alter payout functionality. Treat as a functional refactor unless additional context indicates it addresses a reported security issue.
Security signals we found
Removed URI mutation path that appended query parameters to an externally supplied BIP21 URI
Reduced code complexity and branch count in payout destination handling
Eliminated use of BTCPayServerClient.AppendPayloadToQuery in this code path
Evidence from the diff
The patch refactors BitcoinLikePayoutHandler.InitiatePayment. It removes the UriClaimDestination branch that mutated an existing BIP21 URI’s amount and appended a payout ID query parameter using BTCPayServerClient.AppendPayloadToQuery. It also removes the AddressClaimDestination branch. Both are replaced by a single path using the IBitcoinLikeClaimDestination interface, which generates a new BIP21 URI via Network.GenerateBIP21 and adds the payout ID to QueryParams. The BTCPayServer.Client namespace import is removed. The functional effect is that any payout destination that is a BIP21 URI will now have a fresh BIP21 URI generated from its address, rather than preserving the original URI’s query parameters and structure.
Changed components
BTCPayServer/Data/Payouts/BitcoinLike/BitcoinLikePayoutHandler.csPayout processing / BIP21 URI generationInspect captured patch +4 / −13
### BTCPayServer/Data/Payouts/BitcoinLike/BitcoinLikePayoutHandler.cs
@@ -5,7 +5,6 @@
using System.Threading.Tasks;
using BTCPayServer;
using BTCPayServer.Abstractions.Models;
-using BTCPayServer.Client;
using BTCPayServer.Client.Models;
using BTCPayServer.Data;
using BTCPayServer.Events;
@@ -300,19 +299,11 @@ public async Task<IActionResult> InitiatePayment(string[] payoutIds)
if (payout.GetPayoutMethodId() != PayoutMethodId)
continue;
var claim = await ParseClaimDestination(blob.Destination, default);
- switch (claim.destination)
+ if (claim.destination is IBitcoinLikeClaimDestination bitcoinLikeClaimDestination)
{
- case UriClaimDestination uriClaimDestination:
- uriClaimDestination.BitcoinUrl.Amount = new Money(payout.Amount.Value, MoneyUnit.BTC);
- var newUri = new UriBuilder(uriClaimDestination.BitcoinUrl.Uri);
- BTCPayServerClient.AppendPayloadToQuery(newUri, new KeyValuePair<string, object>("payout", payout.Id));
- bip21.Add(newUri.Uri.ToString());
- break;
- case AddressClaimDestination addressClaimDestination:
- var bip21New = Network.GenerateBIP21(addressClaimDestination.Address.ToString(), payout.Amount.Value);
- bip21New.QueryParams.Add("payout", payout.Id);
- bip21.Add(bip21New.ToString());
- break;
+ var bip21New = Network.GenerateBIP21(bitcoinLikeClaimDestination.Address.ToString(), payout.Amount.Value);
+ bip21New.QueryParams.Add("payout", payout.Id);
+ bip21.Add(bip21New.ToString());
}
}
if (bip21.Any())Why this scored 25/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.