Skip to content

Commit 642c844

Browse files
Merge remote-tracking branch 'origin/main'
2 parents 004013c + e70d288 commit 642c844

File tree

3 files changed

+100
-74
lines changed

3 files changed

+100
-74
lines changed

src/Modix.Bot/Modules/TagModule.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public async Task ModifyTagAsync(
6161
{
6262
name = name.Trim().ToLower();
6363

64+
await _tagService.EnsureUserCanMaintainTagAsync(Context.Guild.Id, name, Context.User.Id);
65+
6466
var currentTagData = await _tagService.GetTagAsync(Context.Guild.Id, name);
6567

6668
if (currentTagData is null)

src/Modix.Services/Moderation/AttachmentBlacklistBehavior.cs

Lines changed: 82 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#nullable enable
22

33
using System.Collections.Generic;
4+
using System.Collections.Immutable;
5+
using System.IO;
46
using System.Linq;
57
using System.Threading;
68
using System.Threading.Tasks;
@@ -21,78 +23,85 @@ namespace Modix.Services.Moderation
2123
public class AttachmentBlacklistBehavior
2224
: INotificationHandler<MessageReceivedNotification>
2325
{
24-
public static readonly IReadOnlyCollection<string> BlacklistedExtensions = new[]
25-
{
26-
".exe",
27-
".dll",
28-
".application",
29-
".msc",
30-
".bat",
31-
".pdb",
32-
".sh",
33-
".com",
34-
".scr",
35-
".msi",
36-
".cmd",
37-
".vbs",
38-
".js",
39-
".reg",
40-
".pif",
41-
".msp",
42-
".hta",
43-
".cpl",
44-
".jar",
45-
".vbe",
46-
".ws",
47-
".wsf",
48-
".wsc",
49-
".wsh",
50-
".ps1",
51-
".ps1xml",
52-
".ps2",
53-
".ps2xml",
54-
".psc1",
55-
".pasc2",
56-
".msh",
57-
".msh1",
58-
".msh2",
59-
".mshxml",
60-
".msh1xml",
61-
".msh2xml",
62-
".scf",
63-
".lnk",
64-
".inf",
65-
".doc",
66-
".xls",
67-
".ppt",
68-
".docm",
69-
".dotm",
70-
".xlsm",
71-
".xltm",
72-
".xlam",
73-
".pptm",
74-
".potm",
75-
".ppam",
76-
".ppsm",
77-
".sldn",
78-
".sb",
79-
".bin",
80-
".com",
81-
".gadget",
82-
".inf1",
83-
".ins",
84-
".inx",
85-
".isu",
86-
".job",
87-
".jse",
88-
".paf",
89-
".rgs",
90-
".sct",
91-
".shb",
92-
".shs",
93-
".u3p",
94-
".vbscript"
95-
};
26+
/// <summary>
27+
/// Gets the set of blacklisted extensions.
28+
/// </summary>
29+
/// <remarks>
30+
/// When adding new extensions, maintain the alphabetical order to improve readability.
31+
/// </remarks>
32+
public static readonly ImmutableHashSet<string> BlacklistedExtensions =
33+
[
34+
".application",
35+
".bat",
36+
".bin",
37+
".cmd",
38+
".com",
39+
".cpl",
40+
".dll",
41+
".doc",
42+
".docm",
43+
".dotm",
44+
".exe",
45+
".gadget",
46+
".hta",
47+
".inf",
48+
".inf1",
49+
".ins",
50+
".inx",
51+
".isu",
52+
".jar",
53+
".job",
54+
".js",
55+
".jse",
56+
".lnk",
57+
".msc",
58+
".msh",
59+
".msh1",
60+
".msh1xml",
61+
".msh2",
62+
".msh2xml",
63+
".mshxml",
64+
".msi",
65+
".msp",
66+
".paf",
67+
".pasc2",
68+
".pdb",
69+
".pdf",
70+
".pif",
71+
".potm",
72+
".ppam",
73+
".ppsm",
74+
".ppt",
75+
".pptm",
76+
".ps1",
77+
".ps1xml",
78+
".ps2",
79+
".ps2xml",
80+
".psc1",
81+
".reg",
82+
".rgs",
83+
".sb",
84+
".scf",
85+
".scr",
86+
".sct",
87+
".sh",
88+
".shb",
89+
".shs",
90+
".sldn",
91+
".u3p",
92+
".vbe",
93+
".vbs",
94+
".vbscript",
95+
".ws",
96+
".wsc",
97+
".wsf",
98+
".wsh",
99+
".xlam",
100+
".xls",
101+
".xlsm",
102+
".xltm",
103+
".zip",
104+
];
96105

97106
public AttachmentBlacklistBehavior(
98107
DesignatedChannelService designatedChannelService,
@@ -151,8 +160,7 @@ public async Task HandleNotificationAsync(
151160
AttachmentBlacklistLogMessages.SuspiciousAttachmentsSearching(_logger);
152161
var blacklistedFilenames = message.Attachments
153162
.Select(attachment => attachment.Filename.ToLower())
154-
.Where(filename => BlacklistedExtensions
155-
.Any(extension => filename.EndsWith(extension)))
163+
.Where(filename => BlacklistedExtensions.Contains(Path.GetExtension(filename)))
156164
.ToArray();
157165

158166
if(!blacklistedFilenames.Any())

src/Modix.Services/Tags/TagService.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public interface ITagService
4242
Task<bool> TagExistsAsync(ulong guildId, string name);
4343

4444
Task RefreshCache(ulong guildId);
45+
46+
Task EnsureUserCanMaintainTagAsync(ulong guildId, string name, ulong currentUserId);
4547
}
4648

4749
internal class TagService : ITagService
@@ -340,6 +342,20 @@ public async Task RefreshCache(ulong guildId)
340342
_tagCache.Set(guildId, tags);
341343
}
342344

345+
public async Task EnsureUserCanMaintainTagAsync(ulong guildId, string name, ulong currentUserId)
346+
{
347+
var tag = await _modixContext
348+
.Set<TagEntity>()
349+
.Include(x => x.OwnerRole)
350+
.Include(x => x.OwnerUser)
351+
.Where(x => x.GuildId == guildId)
352+
.Where(x => x.DeleteActionId == null)
353+
.Where(x => x.Name == name)
354+
.SingleOrDefaultAsync();
355+
356+
await EnsureUserCanMaintainTagAsync(tag, currentUserId);
357+
}
358+
343359
private async Task EnsureUserCanMaintainTagAsync(TagEntity tag, ulong currentUserId)
344360
{
345361
var currentUser = await _userService.GetGuildUserAsync(tag.GuildId, currentUserId);

0 commit comments

Comments
 (0)