Prevent overlapping tags

This commit is contained in:
RogueException
2017-03-31 15:18:35 -03:00
parent 7d1cae8ae8
commit 8dfa0220c3
2 changed files with 23 additions and 2 deletions

View File

@@ -256,6 +256,15 @@ namespace Discord
if (mode != TagHandling.Remove)
{
Emoji emoji = (Emoji)tag.Value;
//Remove if its name contains any bad chars (prevents a few tag exploits)
for (int i = 0; i < emoji.Name.Length; i++)
{
char c = emoji.Name[i];
if (!char.IsLetterOrDigit(c) && c != '_' && c != '-')
return "";
}
switch (mode)
{
case TagHandling.Name:

View File

@@ -126,7 +126,8 @@ namespace Discord.Rest
index = text.IndexOf("@everyone", index);
if (index == -1) break;
tags.Add(new Tag<object>(TagType.EveryoneMention, index, "@everyone".Length, 0, null));
if (!TagOverlaps(tags, index))
tags.Add(new Tag<object>(TagType.EveryoneMention, index, "@everyone".Length, 0, null));
index++;
}
@@ -136,12 +137,23 @@ namespace Discord.Rest
index = text.IndexOf("@here", index);
if (index == -1) break;
tags.Add(new Tag<object>(TagType.HereMention, index, "@here".Length, 0, null));
if (!TagOverlaps(tags, index))
tags.Add(new Tag<object>(TagType.HereMention, index, "@here".Length, 0, null));
index++;
}
return tags.ToImmutable();
}
private static bool TagOverlaps(IReadOnlyList<ITag> tags, int index)
{
for (int i = 0; i < tags.Count; i++)
{
var tag = tags[i];
if (index >= tag.Index && index < tag.Index + tag.Length)
return true;
}
return false;
}
public static ImmutableArray<ulong> FilterTagsByKey(TagType type, ImmutableArray<ITag> tags)
{
return tags