diff --git a/Logic/Support/General.cs b/Logic/Support/General.cs index 14a707b8..d65f63e9 100644 --- a/Logic/Support/General.cs +++ b/Logic/Support/General.cs @@ -36,6 +36,7 @@ namespace Swarmops.Logic.Support return result.ToString(); } + // ReSharper disable once InconsistentNaming -- IPAddress is the canonical writing public static string GetRemoteIPAddressChain() { string forwardedIps = @@ -54,5 +55,24 @@ namespace Swarmops.Logic.Support return result; } + + // ReSharper disable once InconsistentNaming -- IPAddress is the canonical writing + public static string GetMostLikelyRemoteIPAddress() + { + // All of this can be faked trivially by the client, so you can't rely on it for any kind of security. + + string forwardedIps = + HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; + + string directIp = + HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; + + if (!string.IsNullOrEmpty (forwardedIps)) + { + return forwardedIps.Split (',').Last(); + } + + return directIp; + } } } diff --git a/Site5/Pages/v5/Public/Signup.aspx.cs b/Site5/Pages/v5/Public/Signup.aspx.cs index 04af4b7f..52f9663e 100644 --- a/Site5/Pages/v5/Public/Signup.aspx.cs +++ b/Site5/Pages/v5/Public/Signup.aspx.cs @@ -296,7 +296,7 @@ namespace Swarmops.Frontend.Pages.Public try { - string ipAddress = HttpContext.Current.Request.UserHostAddress; + string ipAddress = Logic.Support.SupportFunctions.GetMostLikelyRemoteIPAddress(); NGeoIP.Request request = new Request() {