From 603123777d859404f5068edc2f8618df8545f61a Mon Sep 17 00:00:00 2001 From: spiral Date: Wed, 25 Aug 2021 13:42:08 -0400 Subject: [PATCH] add limits to switch members and proxy tag length --- PluralKit.Bot/Commands/MemberProxy.cs | 2 ++ PluralKit.Bot/Commands/Switch.cs | 2 ++ PluralKit.Core/Utils/Limits.cs | 2 ++ 3 files changed, 6 insertions(+) diff --git a/PluralKit.Bot/Commands/MemberProxy.cs b/PluralKit.Bot/Commands/MemberProxy.cs index f1efb38a..bd0b86e3 100644 --- a/PluralKit.Bot/Commands/MemberProxy.cs +++ b/PluralKit.Bot/Commands/MemberProxy.cs @@ -78,6 +78,8 @@ namespace PluralKit.Bot if (tagToAdd.IsEmpty) throw Errors.EmptyProxyTags(target); if (target.ProxyTags.Contains(tagToAdd)) throw Errors.ProxyTagAlreadyExists(tagToAdd, target); + if (tagToAdd.ProxyString.Length > Limits.MaxProxyTagLength) + throw new PKError($"Proxy tag too long ({tagToAdd.ProxyString.Length} > {Limits.MaxProxyTagLength} characters)."); if (!await WarnOnConflict(tagToAdd)) throw Errors.GenericCancelled(); diff --git a/PluralKit.Bot/Commands/Switch.cs b/PluralKit.Bot/Commands/Switch.cs index fc910de0..80093217 100644 --- a/PluralKit.Bot/Commands/Switch.cs +++ b/PluralKit.Bot/Commands/Switch.cs @@ -40,6 +40,8 @@ namespace PluralKit.Bot // Make sure there are no dupes in the list // We do this by checking if removing duplicate member IDs results in a list of different length if (members.Select(m => m.Id).Distinct().Count() != members.Count) throw Errors.DuplicateSwitchMembers; + if (members.Count > Limits.MaxSwitchMemberCount) + throw new PKError($"Switch contains too many members ({members.Count} > {Limits.MaxSwitchMemberCount} members)."); // Find the last switch and its members if applicable await using var conn = await _db.Obtain(); diff --git a/PluralKit.Core/Utils/Limits.cs b/PluralKit.Core/Utils/Limits.cs index 00f09075..ab419e2e 100644 --- a/PluralKit.Core/Utils/Limits.cs +++ b/PluralKit.Core/Utils/Limits.cs @@ -9,6 +9,8 @@ namespace PluralKit.Core { public static int MaxMembersWarnThreshold (int memberLimit) => memberLimit - 50; public static readonly int MaxGroupCount = 250; public static readonly int MaxDescriptionLength = 1000; + public static readonly int MaxProxyTagLength = 100; + public static readonly int MaxSwitchMemberCount = 150; public static readonly int MaxMemberNameLength = 100; // Fair bit larger than MaxProxyNameLength for bookkeeping public static readonly int MaxGroupNameLength = 100; public static readonly int MaxPronounsLength = 100;