Skip to content

Commit 694321f

Browse files
committed
Adjustments to IPDB Security
1 parent e5e1183 commit 694321f

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

Zolian.Server.Base/Models/Ipdb.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,6 @@ public class Data
7979
[JsonProperty("countryCode")]
8080
public string CountryCode { get; set; }
8181

82-
/// <summary>
83-
/// Name for the country of address
84-
/// </summary>
85-
[JsonProperty("countryName")]
86-
public string CountryName { get; set; }
87-
8882
/// <summary>
8983
/// Usage type - (Reserved, Data Center, Web Hosting, Transit, etc)
9084
/// </summary>
@@ -112,6 +106,12 @@ public class Data
112106
[JsonProperty("isTor")]
113107
public bool IsTor { get; set; }
114108

109+
/// <summary>
110+
/// Name for the country of address
111+
/// </summary>
112+
[JsonProperty("countryName")]
113+
public string CountryName { get; set; }
114+
115115
/// <summary>
116116
/// Number of reports against the Address
117117
/// </summary>

Zolian.Server.Base/Network/Server/BadActor.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ public static async Task<bool> ClientOnBlackListAsync(string remoteIp)
6464
if (response.IsSuccessful)
6565
{
6666
var ipdb = JsonConvert.DeserializeObject<Ipdb>(response.Content!);
67+
var isPublic = ipdb?.Data?.IsPublic ?? false;
68+
var ipVersion = ipdb?.Data?.IpVersion ?? 4;
6769
var abuseScore = ipdb?.Data?.AbuseConfidenceScore ?? 0;
6870
var tor = ipdb?.Data?.IsTor ?? false;
6971
var usageType = ipdb?.Data?.UsageType;
@@ -74,8 +76,11 @@ public static async Task<bool> ClientOnBlackListAsync(string remoteIp)
7476
var isVpnBot = IsVpnBotUsageType(usageType) && abuseScore >= 3;
7577

7678
// Block disallowed, no need to report
77-
if (isDisallowed)
78-
shouldBlock = true;
79+
if (ipVersion == 6 || isPublic == false || isDisallowed || IsBlackListed(isp))
80+
{
81+
IpCache.Set(remoteIp, new IpCacheEntry { IsBlocked = true }, CacheDuration);
82+
return true;
83+
}
7984

8085
if (isVpnBot)
8186
{
@@ -328,12 +333,6 @@ private static void LogTor(string remoteIp, string reason)
328333
ReportTorEndpoint(remoteIp, $"Blocked due to {reason}");
329334
}
330335

331-
private static void LogBlockedType(string remoteIp, string reason)
332-
{
333-
ServerSetup.ConnectionLogger($"Blocking {remoteIp} - Usage: {reason}", LogLevel.Warning);
334-
ReportSuspiciousEndpoint(remoteIp, "Blocked due to Web Spam or Port Scanning");
335-
}
336-
337336
private static bool IsDisallowedUsageType(string? usageType)
338337
{
339338
return usageType switch
@@ -358,5 +357,11 @@ private static bool IsVpnBotUsageType(string? usageType)
358357
_ => false
359358
};
360359

360+
private static bool IsBlackListed(string? isp) => isp switch
361+
{
362+
"Driftnet Ltd" or "DigitalOcean, LLC" => true,
363+
_ => false
364+
};
365+
361366
private static bool IsKeyCodeValid(string? keyCode) => !string.IsNullOrWhiteSpace(keyCode);
362367
}

0 commit comments

Comments
 (0)