aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Users/UserService.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-04-20 18:38:51 -0500
committerGitHub <noreply@github.com>2026-04-20 18:38:51 -0500
commit6ead594b1421e37a7ba1dcf0617958263d064fdb (patch)
tree18c8688fd57469bd335a5ab3998389d8945d1ee9 /src/slskd/Users/UserService.cs
parent95e85cacce4f189e2bc894f81ff53a267e338381 (diff)
parent7033851e42d1412c34c4022f6a8dd1632c64586e (diff)
downloadslskd-6ead594b1421e37a7ba1dcf0617958263d064fdb.tar.gz
Merge pull request #1699 from ofernander/master
feat: add username reg pattern matching to blacklist group
Diffstat (limited to 'src/slskd/Users/UserService.cs')
-rw-r--r--src/slskd/Users/UserService.cs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/slskd/Users/UserService.cs b/src/slskd/Users/UserService.cs
index d8b24f4d..31c1e540 100644
--- a/src/slskd/Users/UserService.cs
+++ b/src/slskd/Users/UserService.cs
@@ -38,6 +38,7 @@ namespace slskd.Users
using System.Collections.Generic;
using System.Linq;
using System.Net;
+ using System.Text.RegularExpressions;
using System.Threading.Tasks;
using NetTools;
using Serilog;
@@ -291,6 +292,8 @@ namespace slskd.Users
/// <returns>A value indicating whether the specified user and/or IP are blacklisted.</returns>
public bool IsBlacklisted(string username, IPAddress ipAddress = null)
{
+ if (username is null) return false;
+
var blacklist = OptionsMonitor.CurrentValue.Transfers.Groups.Blacklisted;
if (blacklist.Members.Contains(username))
@@ -298,6 +301,20 @@ namespace slskd.Users
return true;
}
+ // check username patterns (regex). respects the same case sensitivity flag used by other
+ // user-defined regular expressions throughout the application.
+ if (blacklist.Patterns.Length > 0)
+ {
+ var regexOptions = OptionsMonitor.CurrentValue.Flags.CaseSensitiveRegEx
+ ? RegexOptions.None
+ : RegexOptions.IgnoreCase;
+
+ if (blacklist.Patterns.Any(p => Regex.IsMatch(username, p, regexOptions)))
+ {
+ return true;
+ }
+ }
+
// check the user-curated list of blacklisted CIDRs that exists along with the list of
// blacklisted usernames. these CIDRs should be one-offs and would not be expected to appear in a
// blacklist supplied by a third party (but might?)