java-topology/defects/btcpayserver-0001/patch/btcpayserver-0001.patch
russell@unturf.com c2a1fc15cc undf: assign 928-930; btcpayserver CWE-407 scan (3 defects)
btcpayserver-0001: WalletTransactionInfo.Merge Attachments.Any O(A*B) MEDIUM
btcpayserver-0002: AppService gap-fill series.All O(D*S) LOW-MEDIUM
btcpayserver-0003: StringExtensions.IsValidFileName GetInvalidFileNameChars O(F*I) MEDIUM
2026-03-31 09:39:59 -04:00

24 lines
1.3 KiB
Diff

# UNDF: UNDF-2026-000000928
--- a/BTCPayServer/Data/WalletTransactionInfo.cs
+++ b/BTCPayServer/Data/WalletTransactionInfo.cs
@@ -99,10 +99,14 @@
result.LabelColors = new Dictionary<string, string>(LabelColors);
result.Attachments = new List<Attachment>(Attachments);
+
+ // CWE-407: Attachments.Any() inside Where() is O(A*B) where A = value.Attachments
+ // and B = this.Attachments. Build a HashSet of existing (Id, Type) pairs for O(1) lookup.
+ var existingAttachments = new HashSet<(string Id, string Type)>(
+ Attachments.Select(a => (a.Id, a.Type)));
+
foreach (var valueLabelColor in value.LabelColors)
{
result.LabelColors.TryAdd(valueLabelColor.Key, valueLabelColor.Value);
}
- foreach (var valueAttachment in value.Attachments.Where(valueAttachment => !Attachments.Any(attachment =>
- attachment.Id == valueAttachment.Id && attachment.Type == valueAttachment.Type)))
+ foreach (var valueAttachment in value.Attachments.Where(valueAttachment =>
+ !existingAttachments.Contains((valueAttachment.Id, valueAttachment.Type))))
{
result.Attachments.Add(valueAttachment);
}