added redirected remote ip detection

This commit is contained in:
Nicolas Constant
2022-12-31 00:05:12 -05:00
parent 2542258ce4
commit 8f42032512

View File

@@ -41,6 +41,14 @@ namespace BirdsiteLive.Middlewares
if (_ipWhitelistingSet) if (_ipWhitelistingSet)
{ {
var remoteIp = context.Connection.RemoteIpAddress; var remoteIp = context.Connection.RemoteIpAddress;
var forwardedIp = context.Request.Headers.FirstOrDefault(x => x.Key == "X-Real-IP").Value.ToString();
if (!string.IsNullOrWhiteSpace(forwardedIp))
{
_logger.LogDebug("Redirected IP address detected");
remoteIp = IPAddress.Parse(forwardedIp);
}
_logger.LogDebug("Request from Remote IP address: {RemoteIp}", remoteIp); _logger.LogDebug("Request from Remote IP address: {RemoteIp}", remoteIp);
var bytes = remoteIp.GetAddressBytes(); var bytes = remoteIp.GetAddressBytes();