From aa52f9fc6dc45696f1057f33b95d07553f395f5f Mon Sep 17 00:00:00 2001 From: Qstick Date: Wed, 7 Dec 2022 21:18:17 -0600 Subject: [PATCH] Simplify X-Forwarded-For handling This happens in asp.net middleware now Co-Authored-By: ta264 (cherry picked from commit 16e2d130e6a2e7239bcfe92187a7f990f93eff00) --- .../Extensions/RequestExtensions.cs | 34 +------------------ 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/src/Readarr.Http/Extensions/RequestExtensions.cs b/src/Readarr.Http/Extensions/RequestExtensions.cs index 1928a428a..9798fc915 100644 --- a/src/Readarr.Http/Extensions/RequestExtensions.cs +++ b/src/Readarr.Http/Extensions/RequestExtensions.cs @@ -162,39 +162,7 @@ namespace Readarr.Http.Extensions remoteIP = remoteIP.MapToIPv4(); } - var remoteAddress = 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; + return remoteIP.ToString(); } public static void DisableCache(this IHeaderDictionary headers)