aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2023-10-15 17:33:22 -0500
committerJP Dillingham <jp@dillingham.me>2023-10-15 17:33:22 -0500
commit89528aa6447ec4889c103a1ce26f650e35d4781c (patch)
tree1938ec09e5eeae36e4a0955c593c638ebd4e6865 /src
parentf91bc6ddf2789a16c469f747b5c143c0ca61945f (diff)
downloadslskd-89528aa6447ec4889c103a1ce26f650e35d4781c.tar.gz
check endpoints against blacklisted cidrs
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Application.cs24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs
index 89ff6b27..fc9f71c6 100644
--- a/src/slskd/Application.cs
+++ b/src/slskd/Application.cs
@@ -36,6 +36,7 @@ namespace slskd
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Hosting;
+ using NetTools;
using Serilog;
using Serilog.Events;
using slskd.Configuration;
@@ -457,7 +458,7 @@ namespace slskd
private Task EnqueueDownload(string username, IPEndPoint endpoint, string filename)
{
- if (Options.Groups.Blacklisted.Members.Contains(username))
+ if (IsBlacklisted(username, endpoint.Address))
{
return Task.FromException(new DownloadEnqueueException($"File not shared."));
}
@@ -475,7 +476,7 @@ namespace slskd
{
Metrics.Browse.RequestsReceived.Inc(1);
- if (Options.Groups.Blacklisted.Members.Contains(username))
+ if (IsBlacklisted(username, endpoint.Address))
{
return new BrowseResponse();
}
@@ -899,7 +900,7 @@ namespace slskd
/// <returns>A Task resolving an instance of Soulseek.Directory containing the contents of the requested directory.</returns>
private async Task<Soulseek.Directory> DirectoryContentsResponseResolver(string username, IPEndPoint endpoint, int token, string directory)
{
- if (Options.Groups.Blacklisted.Members.Contains(username))
+ if (IsBlacklisted(username, endpoint.Address))
{
return new Soulseek.Directory(directory);
}
@@ -1094,7 +1095,7 @@ namespace slskd
{
Metrics.Search.RequestsReceived.Inc(1);
- if (Options.Groups.Blacklisted.Members.Contains(username))
+ if (IsBlacklisted(username))
{
return new SearchResponse(username, token, hasFreeUploadSlot: false, uploadSpeed: 0, queueLength: int.MaxValue, fileList: Enumerable.Empty<Soulseek.File>());
}
@@ -1316,5 +1317,20 @@ namespace slskd
throw;
}
}
+
+ private bool IsBlacklisted(string username, IPAddress ipAddress = null)
+ {
+ if (Options.Groups.Blacklisted.Members.Contains(username))
+ {
+ return true;
+ }
+
+ if (ipAddress is not null && Options.Groups.Blacklisted.Cidrs.Select(c => IPAddressRange.Parse(c)).Any(range => range.Contains(ipAddress)))
+ {
+ return true;
+ }
+
+ return false;
+ }
}
}