Skip to content

Commit

Permalink
Only localhost is exempt from IP spam checking now
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Aug 17, 2021
1 parent f7d5d91 commit 0afcb99
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
3 changes: 2 additions & 1 deletion MCGalaxy/Modules/Security/IPThrottler.cs
Expand Up @@ -51,7 +51,7 @@ public sealed class IPThrottler : Plugin

void HandleConnectionReceived(Socket s, ref bool cancel) {
IPAddress ip = SocketUtil.GetIP(s);
if (!Server.Config.IPSpamCheck || IPUtil.IsLocal(ip)) return;
if (!Server.Config.IPSpamCheck || IPAddress.IsLoopback(ip)) return;

DateTime now = DateTime.UtcNow;
string ipStr = ip.ToString();
Expand All @@ -63,6 +63,7 @@ public sealed class IPThrottler : Plugin
ips[ipStr] = entry;
}

// Check if that IP is repeatedly trying to connect
if (entry.BlockedUntil < now) {
if (!entry.AddSpamEntry(Server.Config.IPSpamCount, Server.Config.IPSpamInterval)) {
entry.BlockedUntil = now.Add(Server.Config.IPSpamBlockTime);
Expand Down
15 changes: 0 additions & 15 deletions MCGalaxy/Network/Utils/Utils.cs
Expand Up @@ -39,21 +39,6 @@ public static class IPUtil
// TODO: Are there more IPv6 address ranges than just this?
return ip.IsIPv6LinkLocal;
}

/// <summary> Returns whether the given IP is a loopback address
/// or an address mapped to this computer's host </summary>
public static bool IsLocal(IPAddress ip) {
try {
if (IPAddress.IsLoopback(ip)) return true;

IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
foreach (IPAddress localIP in localIPs) {
if (ip.Equals(localIP)) return true;
}
}
catch { }
return false;
}

/// <summary> Returns whether the given IP is an IPv4 mapped IPv6 address </summary>
public static bool IsIPv4Mapped(IPAddress ip) {
Expand Down

0 comments on commit 0afcb99

Please sign in to comment.