From e2116712e7d1cfbf594dad829ff1d62dac9ee3b7 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Mon, 5 Jul 2021 16:08:13 -0500 Subject: [PATCH] pass x-forwarded-for to properly log proxied login/logout --- WebfrontCore/Controllers/API/ClientController.cs | 8 ++++++-- WebfrontCore/Controllers/AccountController.cs | 9 +++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/WebfrontCore/Controllers/API/ClientController.cs b/WebfrontCore/Controllers/API/ClientController.cs index f01de4e30..792b5477c 100644 --- a/WebfrontCore/Controllers/API/ClientController.cs +++ b/WebfrontCore/Controllers/API/ClientController.cs @@ -125,7 +125,9 @@ namespace WebfrontCore.Controllers.API Origin = privilegedClient, Type = GameEvent.EventType.Login, Owner = Manager.GetServers().First(), - Data = HttpContext.Connection.RemoteIpAddress.ToString() + Data = HttpContext.Request.Headers.ContainsKey("X-Forwarded-For") + ? HttpContext.Request.Headers["X-Forwarded-For"].ToString() + : HttpContext.Connection.RemoteIpAddress.ToString() }); return Ok(); @@ -152,7 +154,9 @@ namespace WebfrontCore.Controllers.API Origin = Client, Type = GameEvent.EventType.Logout, Owner = Manager.GetServers().First(), - Data = HttpContext.Connection.RemoteIpAddress.ToString() + Data = HttpContext.Request.Headers.ContainsKey("X-Forwarded-For") + ? HttpContext.Request.Headers["X-Forwarded-For"].ToString() + : HttpContext.Connection.RemoteIpAddress.ToString() }); } diff --git a/WebfrontCore/Controllers/AccountController.cs b/WebfrontCore/Controllers/AccountController.cs index cd80294e0..91d283339 100644 --- a/WebfrontCore/Controllers/AccountController.cs +++ b/WebfrontCore/Controllers/AccountController.cs @@ -7,6 +7,7 @@ using System; using System.Linq; using System.Security.Claims; using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; namespace WebfrontCore.Controllers { @@ -57,7 +58,9 @@ namespace WebfrontCore.Controllers Origin = privilegedClient, Type = GameEvent.EventType.Login, Owner = Manager.GetServers().First(), - Data = HttpContext.Connection.RemoteIpAddress.ToString() + Data = HttpContext.Request.Headers.ContainsKey("X-Forwarded-For") + ? HttpContext.Request.Headers["X-Forwarded-For"].ToString() + : HttpContext.Connection.RemoteIpAddress.ToString() }); return Ok(); @@ -82,7 +85,9 @@ namespace WebfrontCore.Controllers Origin = Client, Type = GameEvent.EventType.Logout, Owner = Manager.GetServers().First(), - Data = HttpContext.Connection.RemoteIpAddress.ToString() + Data = HttpContext.Request.Headers.ContainsKey("X-Forwarded-For") + ? HttpContext.Request.Headers["X-Forwarded-For"].ToString() + : HttpContext.Connection.RemoteIpAddress.ToString() }); }