What changed, and why it matters
This commit is titled 'Various optimizations' and makes small code cleanups across four files. The most notable change is in a Razor view where tooltip HTML is now generated more safely: previously, user-controlled text was inserted directly into an HTML attribute without quotes, which could have allowed special characters to break out of the attribute. The other changes are regex performance tweaks and a minor refactoring of derivation scheme parsing. There is no explicit security claim by the project, and no independent researcher is credited.
Review whether the unquoted tooltip attribute was exploitable in deployed versions and consider adding output-encoding tests for the TruncateCenter component. The regex hardenings are good defensive changes and should be kept.
Security signals we found
Unquoted HTML attribute in tooltip rendering was replaced with quoted, Razor-encoded attribute
Regex interpolation pattern tightened to reject nested braces
Regex made NonBacktracking, reducing ReDoS surface
No explicit security disclosure or CVE referenced in commit
Evidence from the diff
The Default.cshtml change refactors a span whose tooltip title was rendered via string interpolation: $"data-bs-toggle=tooltip title={Model.Text}". This produced unquoted attribute values, creating an HTML attribute-injection risk if Model.Text contained spaces or quote characters. The patch now uses a proper Razor attribute syntax title="@Model.Text", which encodes the value. The TextTemplate.cs regex change tightens interpolation matching from [^}]+ to [^{}]+, preventing nested braces from being mis-parsed. DerivationSchemeParser.cs replaces a static Regex.Match call with a cached NonBacktracking regex, and UIStoreOnChainWalletsController.cs reuses the new helper. These are defensive hardenings rather than clear-cut vulnerability fixes.
Changed components
BTCPayServer.Common/TextTemplate.csBTCPayServer/Components/TruncateCenter/Default.cshtmlBTCPayServer/DerivationSchemeParser.csBTCPayServer/Plugins/Wallets/Controllers/UIStoreOnChainWalletsController.csInspect captured patch +19 / −14
### BTCPayServer.Common/TextTemplate.cs
@@ -10,7 +10,7 @@ namespace BTCPayServer;
public class TextTemplate(string template)
{
public const int MaxUrlLength = 8192;
- static readonly Regex _interpolationRegex = new Regex(@"\{([^}]+)\}", RegexOptions.Compiled | RegexOptions.CultureInvariant);
+ static readonly Regex _interpolationRegex = new Regex(@"\{([^{}]+)\}", RegexOptions.Compiled | RegexOptions.CultureInvariant);
public static TextTemplate CreateUrlTemplate(string template) =>
new TextTemplate(template)
### BTCPayServer/Components/TruncateCenter/Default.cshtml
@@ -23,10 +23,20 @@
}
else
{
- <span class="truncate-center-truncated" @(Model.IsTruncated ? $"data-bs-toggle=tooltip title={Model.Text}" : "")>
- <span class="truncate-center-start">@Model.Start</span>
- <span class="truncate-center-end">@Model.End</span>
- </span>
+ @if (Model.IsTruncated)
+ {
+ <span class="truncate-center-truncated" data-bs-toggle="tooltip" title="@Model.Text">
+ <span class="truncate-center-start">@Model.Start</span>
+ <span class="truncate-center-end">@Model.End</span>
+ </span>
+ }
+ else
+ {
+ <span class="truncate-center-truncated">
+ <span class="truncate-center-start">@Model.Start</span>
+ <span class="truncate-center-end">@Model.End</span>
+ </span>
+ }
<span class="truncate-center-text">@Model.Text</span>
}
@if (Model.Copy)
### BTCPayServer/DerivationSchemeParser.cs
@@ -37,7 +37,8 @@ public DerivationSchemeParser(BTCPayNetwork expectedNetwork)
}
}
- public static bool MaybeOD(string xpub) => Regex.Match(xpub, @"\(.*?\)").Success;
+ static readonly Regex _maybeODRegex = new Regex(@"\(.*?\)", RegexOptions.NonBacktracking);
+ public static bool MaybeOD(string xpub) => _maybeODRegex.IsMatch(xpub);
/// <summary>
/// Parse an output descriptor into a <see cref="DerivationSchemeSettings"/>
/// </summary>
@@ -320,11 +321,7 @@ public DerivationStrategyBase Parse(string str)
catch { continue; }
}
- str = string.Join('-', parts.Where(p => !IsLabel(p)));
- foreach (var label in hintedLabels)
- {
- str = $"{str}-[{label}]";
- }
+ str = string.Join('-', parts.Where(p => !IsLabel(p)).Concat(hintedLabels.Select(label => $"[{label}]")));
return BtcPayNetwork.NBXplorerNetwork.DerivationStrategyFactory.Parse(str);
}
### BTCPayServer/Plugins/Wallets/Controllers/UIStoreOnChainWalletsController.cs
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
-using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using BTCPayServer.Abstractions.Constants;
@@ -816,8 +815,7 @@ private string WalletRemoveWarning(bool isHotWallet, string cryptoCode)
public static DerivationSchemeSettings ParseDerivationStrategy(string derivationScheme, BTCPayNetwork network)
{
var parser = new DerivationSchemeParser(network);
- var isOD = Regex.Match(derivationScheme, @"\(.*?\)");
- if (isOD.Success)
+ if (DerivationSchemeParser.MaybeOD(derivationScheme))
{
return parser.ParseOD(derivationScheme);
}Why this scored 24/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.