diff --git a/BTCPayServer/Controllers/WalletsController.cs b/BTCPayServer/Controllers/WalletsController.cs index 874479b1a..45bf13b30 100644 --- a/BTCPayServer/Controllers/WalletsController.cs +++ b/BTCPayServer/Controllers/WalletsController.cs @@ -90,6 +90,9 @@ namespace BTCPayServer.Controllers "#000000", "#cc317c", }; + + const int MaxLabelSize = 20; + const int MaxCommentSize = 200; [HttpPost] [Route("{walletId}")] public async Task ModifyTransaction( @@ -127,7 +130,7 @@ namespace BTCPayServer.Controllers var walletTransactionsInfo = await walletTransactionsInfoAsync; if (addlabel != null) { - addlabel = addlabel.Trim().ToLowerInvariant(); + addlabel = addlabel.Trim().ToLowerInvariant().Truncate(MaxLabelSize); var labels = walletBlobInfo.GetLabels(); if (!walletTransactionsInfo.TryGetValue(transactionId, out var walletTransactionInfo)) { @@ -154,7 +157,7 @@ namespace BTCPayServer.Controllers } else if (removelabel != null) { - removelabel = removelabel.Trim().ToLowerInvariant(); + removelabel = removelabel.Trim().ToLowerInvariant().Truncate(MaxLabelSize); if (walletTransactionsInfo.TryGetValue(transactionId, out var walletTransactionInfo)) { if (walletTransactionInfo.Labels.Remove(removelabel)) @@ -171,7 +174,7 @@ namespace BTCPayServer.Controllers } else if (addcomment != null) { - addcomment = addcomment.Trim(); + addcomment = addcomment.Trim().Truncate(MaxCommentSize); if (!walletTransactionsInfo.TryGetValue(transactionId, out var walletTransactionInfo)) { walletTransactionInfo = new WalletTransactionInfo(); diff --git a/BTCPayServer/Extensions.cs b/BTCPayServer/Extensions.cs index f008ea785..4dc0f2c55 100644 --- a/BTCPayServer/Extensions.cs +++ b/BTCPayServer/Extensions.cs @@ -40,6 +40,12 @@ namespace BTCPayServer { public static class Extensions { + public static string Truncate(this string value, int maxLength) + { + if (string.IsNullOrEmpty(value)) + return value; + return value.Length <= maxLength ? value : value.Substring(0, maxLength); + } public static IServiceCollection AddStartupTask(this IServiceCollection services) where T : class, IStartupTask => services.AddTransient(); diff --git a/BTCPayServer/Views/Wallets/WalletTransactions.cshtml b/BTCPayServer/Views/Wallets/WalletTransactions.cshtml index b8f1b4da6..1cdaa6a66 100644 --- a/BTCPayServer/Views/Wallets/WalletTransactions.cshtml +++ b/BTCPayServer/Views/Wallets/WalletTransactions.cshtml @@ -87,7 +87,7 @@