added redirected remote ip detection

This commit is contained in:
Nicolas Constant 2022-12-31 00:05:12 -05:00
parent 2542258ce4
commit 8f42032512
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
1 changed files with 8 additions and 0 deletions

View File

@ -41,6 +41,14 @@ namespace BirdsiteLive.Middlewares
if (_ipWhitelistingSet)
{
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);
var bytes = remoteIp.GetAddressBytes();