Merge pull request #7810 from efeesrefinal/fix/wallet-transaction-filters
What changed, and why it matters
This commit fixes two bugs in BTCPay Server's wallet transaction API. First, when users filtered transactions by both status (confirmed/unconfirmed) and label, the same transaction could appear twice in the results because the filtering logic added the transaction once for matching the label and again for matching the status. Second, two API endpoints that look up a single transaction by ID would crash if given an invalid transaction ID instead of returning a proper 'not found' error. The patch corrects the filtering logic and safely handles malformed transaction IDs.
No immediate security response required. This is a routine bug-fix merge. Operators should ensure they are running a version that includes this commit to avoid API errors and inconsistent wallet transaction listings. Reviewers may want to verify that other endpoints using uint256.Parse perform similar input validation.
Security signals we found
Fixes duplicate entries in API query results due to incorrect filter composition
Replaces unsafe uint256.Parse with uint256.TryParse to prevent unhandled exceptions on malformed input
Adds server-side input validation returning structured 404 API error for invalid transaction IDs
Adds regression tests for combined filter behavior and invalid transaction ID handling
Evidence from the diff
The patch modifies GreenfieldStoreOnChainWalletsController.cs. In ShowOnChainWalletTransactions, the previous code used separate if-blocks that each called filteredList.Add(t), causing duplicate entries when both labelFilter and statusFilter matched. The new code checks both conditions and only adds the transaction once at the end, using continue to skip non-matching entries. It also changes GetOnChainWalletTransaction and PatchOnChainWalletTransaction to use uint256.TryParse instead of uint256.Parse, returning a 404 ‘transaction-not-found’ error for invalid IDs rather than throwing an unhandled exception. Tests are added to verify combined filters return a single result and that invalid transaction IDs return the expected API error. A swagger description update clarifies that labelFilter and statusFilter are combined with AND logic.
Changed components
BTCPayServer/Plugins/Wallets/Controllers/GreenfieldStoreOnChainWalletsController.csBTCPayServer.Tests/GreenfieldAPITests.csBTCPayServer/wwwroot/swagger/v1/swagger.template.stores-wallet.on-chain.jsonInspect captured patch +27 / −9
### BTCPayServer.Tests/GreenfieldAPITests.cs
@@ -3374,6 +3374,18 @@ await client.ShowOnChainWalletTransactions(walletId.StoreId, walletId.CryptoCode
await client.ShowOnChainWalletTransactions(walletId.StoreId, walletId.CryptoCode), data => data.TransactionHash == txdata.TransactionHash);
Assert.Contains(
await client.ShowOnChainWalletTransactions(walletId.StoreId, walletId.CryptoCode, null, "test label"), data => data.TransactionHash == txdata.TransactionHash);
+ // Both filters must match, and a transaction is listed once
+ Assert.Equal(txdata.TransactionHash, Assert.Single(
+ await client.ShowOnChainWalletTransactions(walletId.StoreId, walletId.CryptoCode,
+ new[] { TransactionStatus.Unconfirmed }, "test label")).TransactionHash);
+ Assert.Empty(
+ await client.ShowOnChainWalletTransactions(walletId.StoreId, walletId.CryptoCode,
+ new[] { TransactionStatus.Confirmed }, "test label"));
+ await AssertEx.AssertApiError("transaction-not-found", () =>
+ client.GetOnChainWalletTransaction(walletId.StoreId, walletId.CryptoCode, "invalid"));
+ await AssertEx.AssertApiError("transaction-not-found", () =>
+ client.PatchOnChainWalletTransaction(walletId.StoreId, walletId.CryptoCode, "invalid",
+ new PatchOnChainTransactionRequest(), true));
// unsigned PSBT creation and broadcast endpoint
var psbtDestination = await client.GetOnChainWalletReceiveAddress(walletId.StoreId, walletId.CryptoCode, true);
### BTCPayServer/Plugins/Wallets/Controllers/GreenfieldStoreOnChainWalletsController.cs
@@ -197,17 +197,18 @@ public async Task<IActionResult> ShowOnChainWalletTransactions(
if (!string.IsNullOrWhiteSpace(labelFilter))
{
walletTransactionsInfoAsync.TryGetValue(t.TransactionId.ToString(), out var transactionInfo);
- if (transactionInfo?.LabelColors.ContainsKey(labelFilter) is true)
- filteredList.Add(t);
+ if (transactionInfo?.LabelColors.ContainsKey(labelFilter) is not true)
+ continue;
}
if (statusFilter?.Any() is true)
{
- if (statusFilter.Contains(TransactionStatus.Confirmed) && t.Confirmations != 0)
- filteredList.Add(t);
- else if (statusFilter.Contains(TransactionStatus.Unconfirmed) && t.Confirmations == 0)
- filteredList.Add(t);
+ var status = t.Confirmations != 0 ? TransactionStatus.Confirmed : TransactionStatus.Unconfirmed;
+ if (!statusFilter.Contains(status))
+ continue;
}
+
+ filteredList.Add(t);
}
txs = filteredList;
@@ -231,7 +232,9 @@ public async Task<IActionResult> GetOnChainWalletTransaction(string storeId, str
return actionResult;
var wallet = btcPayWalletProvider.GetWallet(network);
- var tx = await wallet.FetchTransaction(derivationScheme.AccountDerivation, uint256.Parse(transactionId));
+ var tx = uint256.TryParse(transactionId, out var transactionHash)
+ ? await wallet.FetchTransaction(derivationScheme.AccountDerivation, transactionHash)
+ : null;
if (tx is null)
{
return this.CreateAPIError(404, "transaction-not-found", "The transaction was not found.");
@@ -261,7 +264,10 @@ public async Task<IActionResult> PatchOnChainWalletTransaction(
return actionResult;
var wallet = btcPayWalletProvider.GetWallet(network);
- var transactionHash = uint256.Parse(transactionId);
+ if (!uint256.TryParse(transactionId, out var transactionHash))
+ {
+ return this.CreateAPIError(404, "transaction-not-found", "The transaction was not found.");
+ }
var tx = await wallet.FetchTransaction(derivationScheme.AccountDerivation, transactionHash);
if (!force && tx is null)
{
### BTCPayServer/wwwroot/swagger/v1/swagger.template.stores-wallet.on-chain.json
@@ -260,7 +260,7 @@
"name": "labelFilter",
"in": "query",
"required": false,
- "description": "Transaction label to filter by",
+ "description": "Transaction label to filter by. When combined with `statusFilter`, only transactions matching both are returned",
"schema": {
"type": "string"
},Why this scored 29/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.