mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-11 07:37:10 -07:00
Simplify X-Forwarded-For handling
This happens in asp.net middleware now Co-Authored-By: ta264 <ta264@users.noreply.github.com> (cherry picked from commit 16e2d130e6a2e7239bcfe92187a7f990f93eff00)
This commit is contained in:
parent
980f8f0408
commit
73a3e3f4e3
1 changed files with 1 additions and 33 deletions
|
@ -162,39 +162,7 @@ namespace Lidarr.Http.Extensions
|
||||||
remoteIP = remoteIP.MapToIPv4();
|
remoteIP = remoteIP.MapToIPv4();
|
||||||
}
|
}
|
||||||
|
|
||||||
var remoteAddress = remoteIP.ToString();
|
return remoteIP.ToString();
|
||||||
|
|
||||||
// Only check if forwarded by a local network reverse proxy
|
|
||||||
if (remoteIP.IsLocalAddress())
|
|
||||||
{
|
|
||||||
var realIPHeader = request.Headers["X-Real-IP"];
|
|
||||||
if (realIPHeader.Any())
|
|
||||||
{
|
|
||||||
return realIPHeader.First().ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
var forwardedForHeader = request.Headers["X-Forwarded-For"];
|
|
||||||
if (forwardedForHeader.Any())
|
|
||||||
{
|
|
||||||
// Get the first address that was forwarded by a local IP to prevent remote clients faking another proxy
|
|
||||||
foreach (var forwardedForAddress in forwardedForHeader.SelectMany(v => v.Split(',')).Select(v => v.Trim()).Reverse())
|
|
||||||
{
|
|
||||||
if (!IPAddress.TryParse(forwardedForAddress, out remoteIP))
|
|
||||||
{
|
|
||||||
return remoteAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!remoteIP.IsLocalAddress())
|
|
||||||
{
|
|
||||||
return forwardedForAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
remoteAddress = forwardedForAddress;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return remoteAddress;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DisableCache(this IHeaderDictionary headers)
|
public static void DisableCache(this IHeaderDictionary headers)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue