Harden wallet error handling and PSBT input (#7701)
What changed, and why it matters
This commit tightens up how BTCPay Server handles user-supplied PSBT (Bitcoin transaction) data. It adds a size limit check for PSBTs pasted as text (previously only file uploads were checked) and stops including the raw error message from a failed payjoin receiver in the user-facing error. These changes reduce the risk of oversized input causing resource problems and prevent a malicious or misbehaving payjoin receiver from injecting text into the server's error pages.
Review whether 500 KB remains an appropriate PSBT size bound for your deployment and consider adding similar length guards to any other PSBT ingestion paths. If running an older release, patch to a version containing this commit to reduce exposure to oversized PSBT parsing and payjoin error-message injection.
Security signals we found
New input-size limit on pasted PSBT strings (500 KB) to match file-upload limit
Removal of attacker-controlled exception message from user-facing payjoin error output
Addition of unit test for oversized textual PSBT rejection
Commit title explicitly describes hardening of wallet error handling and PSBT input
Evidence from the diff
The patch adds a 500 KB maximum length check for textual PSBT input in WalletPSBTViewModel.GetPSBT(), mirroring the existing UploadedPSBTFile.Length check. It also changes the PayjoinReceiverException handler in UIWalletsController.PSBT.cs to emit a fixed localized string instead of interpolating ex.Message. A unit test verifies the oversized textual PSBT rejection. The commit message frames this as ‘hardening’ wallet error handling and PSBT input.
Changed components
BTCPayServer.Plugins.Wallets.Views.ViewModels.WalletPSBTViewModelBTCPayServer.Plugins.Wallets.Controllers.UIWalletsController.PSBTBTCPayServer.Tests.PSBTTestsInspect captured patch +32 / −3
### BTCPayServer.Tests/PSBTTests.cs
@@ -1,12 +1,29 @@
using System.Linq;
using System.Threading.Tasks;
+using BTCPayServer.Plugins.Wallets.Views.ViewModels;
+using Microsoft.AspNetCore.Mvc.ModelBinding;
using NBitcoin;
using Xunit;
namespace BTCPayServer.Tests
{
public class PSBTTests(ITestOutputHelper helper) : UnitTestBase(helper)
{
+ [Fact]
+ [Trait("FastTest", "FastTest")]
+ public async Task RejectsOversizedTextualPSBTBeforeParsing()
+ {
+ var modelState = new ModelStateDictionary();
+ var vm = new WalletPSBTViewModel
+ {
+ PSBT = new string('A', 500 * 1024 + 1)
+ };
+
+ Assert.Null(await vm.GetPSBT(Network.RegTest, modelState));
+ Assert.False(modelState.IsValid);
+ Assert.Contains(modelState["PSBT"].Errors, error => error.ErrorMessage == "The PSBT is too large.");
+ }
+
[Fact]
public void AddsWitnessUtxoToSegwitInputs()
{
### BTCPayServer/Plugins/Wallets/Controllers/UIWalletsController.PSBT.cs
@@ -526,9 +526,9 @@ public async Task<IActionResult> WalletPSBTReady(
return ViewVault(walletId, vm);
}
}
- catch (PayjoinReceiverException ex)
+ catch (PayjoinReceiverException)
{
- error = StringLocalizer["The payjoin receiver could not complete the payjoin: {0}", ex.Message];
+ error = StringLocalizer["The payjoin receiver could not complete the payjoin request."];
}
catch (PayjoinSenderException ex)
{
### BTCPayServer/Plugins/Wallets/Views/ViewModels/WalletPSBTViewModel.cs
@@ -11,6 +11,8 @@ namespace BTCPayServer.Plugins.Wallets.Views.ViewModels
{
public class WalletPSBTViewModel : WalletPSBTReadyViewModel
{
+ private const int MaxPSBTLength = 500 * 1024;
+
public string CryptoCode { get; set; }
public string Decoded { get; set; }
string _FileName;
@@ -58,8 +60,12 @@ public string FileName
{
if (UploadedPSBTFile != null)
{
- if (UploadedPSBTFile.Length > 500 * 1024)
+ if (UploadedPSBTFile.Length > MaxPSBTLength)
+ {
+ modelState.AddModelError(nameof(PSBT), "The PSBT is too large.");
+ InvalidPSBT = true;
return null;
+ }
try
{
@@ -87,6 +93,12 @@ public string FileName
modelState.Remove(nameof(PSBT));
InvalidPSBT = false;
}
+ if (PSBT?.Length > MaxPSBTLength)
+ {
+ modelState.AddModelError(nameof(PSBT), "The PSBT is too large.");
+ InvalidPSBT = true;
+ return null;
+ }
if (!string.IsNullOrEmpty(PSBT))
{
tryWhy this scored 51/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.