File tree Expand file tree Collapse file tree 1 file changed +82
-74
lines changed
src/Modix.Services/Moderation Expand file tree Collapse file tree 1 file changed +82
-74
lines changed Original file line number Diff line number Diff line change 11#nullable enable
22
33using System . Collections . Generic ;
4+ using System . Collections . Immutable ;
5+ using System . IO ;
46using System . Linq ;
57using System . Threading ;
68using 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 ( ) )
You can’t perform that action at this time.
0 commit comments