Update NBitcoin and avoid repeated PSBT finalization work (#7765)
What changed, and why it matters
This commit updates a Bitcoin library (NBitcoin) to a newer version and simplifies how the app checks whether a transaction proposal (PSBT) is properly finalized. It also tightens access control: if a wallet command is unrecognized, the request is now rejected with a bad-request error instead of falling back to a weaker 'view only' permission. The changes look like routine maintenance plus a small hardening fix, not a clear response to a disclosed security bug.
Review the NBitcoin 10.0.19 release notes for any security-relevant fixes. Verify that the new TryFinalize behavior matches the previous custom logic and that the authorization change does not break legitimate commands. No urgent action is indicated by the diff alone.
Security signals we found
Dependency update to newer NBitcoin patch version
Removal of custom PSBT finalization loop in favor of library API
Authorization policy switch default changed from CanViewWallet to null, with BadRequest for unknown commands
Evidence from the diff
The patch bumps NBitcoin from 10.0.17 to 10.0.19 across three project files. In UIWalletsController.PSBT.cs it replaces a hand-rolled per-input finalization loop with the library’s new psbtObject.TryFinalize(out var sanityErrors) API. It also changes the command-to-policy switch so the default case returns null and the controller returns BadRequest() for unrecognized commands, rather than defaulting to WalletPolicies.CanViewWallet.
Changed components
BTCPayServer.Client/BTCPayServer.Client.csprojBTCPayServer.Rating/BTCPayServer.Rating.csprojBTCPayServer/BTCPayServer.csprojBTCPayServer/Plugins/Wallets/Controllers/UIWalletsController.PSBT.csInspect captured patch +8 / −24
### BTCPayServer.Client/BTCPayServer.Client.csproj
@@ -31,7 +31,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="BTCPayServer.Lightning.Common" Version="1.7.4" />
- <PackageReference Include="NBitcoin" Version="10.0.17" />
+ <PackageReference Include="NBitcoin" Version="10.0.19" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
</ItemGroup>
<ItemGroup>
### BTCPayServer.Rating/BTCPayServer.Rating.csproj
@@ -6,7 +6,7 @@
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="5.9.0" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
- <PackageReference Include="NBitcoin" Version="10.0.17" />
+ <PackageReference Include="NBitcoin" Version="10.0.19" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="DigitalRuby.ExchangeSharp" Version="1.2.1" />
</ItemGroup>
### BTCPayServer/BTCPayServer.csproj
@@ -34,7 +34,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
- <PackageReference Include="NBitcoin" Version="10.0.17" />
+ <PackageReference Include="NBitcoin" Version="10.0.19" />
<PackageReference Include="YamlDotNet" Version="18.1.0" />
<PackageReference Include="BIP78.Sender" Version="0.2.5" />
<PackageReference Include="BTCPayServer.Hwi" Version="2.0.6" />
### BTCPayServer/Plugins/Wallets/Controllers/UIWalletsController.PSBT.cs
@@ -384,26 +384,8 @@ private async Task FetchTransactionDetails(WalletId walletId, DerivationSchemeSe
vm.FeeRate = feeRate.ToString();
}
- if (!psbtObject.IsAllFinalized())
- {
- var sanityErrors = new List<PSBTError>();
- foreach (var input in psbtObject.Inputs)
- {
- if (input.IsFinalized())
- continue;
-
- if (input.GetSignableCoin(out var missingCoin) is null)
- {
- sanityErrors.Add(new PSBTError(input.Index, missingCoin));
- }
- else if (!input.TryFinalizeInput(out var err))
- {
- sanityErrors.Add(err[0]);
- }
- }
- if (sanityErrors.Count > 0)
- vm.SetErrors(sanityErrors);
- }
+ if (!psbtObject.IsAllFinalized() && !psbtObject.TryFinalize(out var sanityErrors))
+ vm.SetErrors(sanityErrors);
var combinedTypeIds = inputToObjects.Values.SelectMany(ids => ids).Concat(outputToObjects.Values)
.DistinctBy(id => $"{id.Type}:{id.Id}").ToArray();
@@ -456,8 +438,10 @@ public async Task<IActionResult> WalletPSBTReady(
{
"decode" or "analyze-psbt" => WalletPolicies.CanSignWalletTransactions,
"broadcast" or "payjoin" => WalletPolicies.CanBroadcastWalletTransactions,
- _ => WalletPolicies.CanViewWallet
+ _ => null
};
+ if (requiredPolicy is null)
+ return BadRequest();
if (!(await authorizationService.AuthorizeAsync(User, walletId.StoreId, requiredPolicy)).Succeeded)
return Forbid();
if (command == "payjoin" &&Why this scored 23/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.