mirror of
https://github.com/Radarr/Radarr
synced 2025-02-24 07:10:57 +00:00
Fixed: Real IP Logging when IPv4 mapped as IPv6 (#6362)
This commit is contained in:
parent
ba1637087e
commit
6f0d5a0583
1 changed files with 15 additions and 2 deletions
|
@ -95,10 +95,23 @@ public static string GetRemoteIP(this NancyContext context)
|
||||||
}
|
}
|
||||||
|
|
||||||
var remoteAddress = context.Request.UserHostAddress;
|
var remoteAddress = context.Request.UserHostAddress;
|
||||||
IPAddress remoteIP;
|
|
||||||
|
IPAddress.TryParse(remoteAddress, out IPAddress remoteIP);
|
||||||
|
|
||||||
|
if (remoteIP == null)
|
||||||
|
{
|
||||||
|
return remoteAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (remoteIP.IsIPv4MappedToIPv6)
|
||||||
|
{
|
||||||
|
remoteIP = remoteIP.MapToIPv4();
|
||||||
|
}
|
||||||
|
|
||||||
|
remoteAddress = remoteIP.ToString();
|
||||||
|
|
||||||
// Only check if forwarded by a local network reverse proxy
|
// Only check if forwarded by a local network reverse proxy
|
||||||
if (IPAddress.TryParse(remoteAddress, out remoteIP) && remoteIP.IsLocalAddress())
|
if (remoteIP.IsLocalAddress())
|
||||||
{
|
{
|
||||||
var realIPHeader = context.Request.Headers["X-Real-IP"];
|
var realIPHeader = context.Request.Headers["X-Real-IP"];
|
||||||
if (realIPHeader.Any())
|
if (realIPHeader.Any())
|
||||||
|
|
Loading…
Reference in a new issue