diff --git a/src/NuGetGallery.Core/Infrastructure/TableErrorLog.cs b/src/NuGetGallery.Core/Infrastructure/TableErrorLog.cs index 314f16a220..8cefe9c7f1 100644 --- a/src/NuGetGallery.Core/Infrastructure/TableErrorLog.cs +++ b/src/NuGetGallery.Core/Infrastructure/TableErrorLog.cs @@ -186,7 +186,7 @@ public override string Log(Error error) return pos.ToString(CultureInfo.InvariantCulture); } - private void Obfuscate(Error error) + public static void Obfuscate(Error error) { error.User = string.Empty; if (error.Form != null) @@ -218,10 +218,19 @@ private void Obfuscate(Error error) error.ServerVariables["HTTP_X_NUGET_APIKEY"] = string.Empty; - var forwardedIps = error.ServerVariables["HTTP_X_FORWARDED_FOR"].Split(','); - var obfuscatedIps = forwardedIps.Select(Obfuscator.ObfuscateIp); - - error.ServerVariables["HTTP_X_FORWARDED_FOR"] = string.Join(",", obfuscatedIps); + var forwardedIps = error.ServerVariables["HTTP_X_FORWARDED_FOR"]? + .Split(',') + .Select(x => x.Trim()) + .Where(x => x.Length > 0) + .ToList(); + if (forwardedIps != null) + { + var obfuscatedIps = string.Join(",", forwardedIps.Select(Obfuscator.ObfuscateIp)); + if (!string.IsNullOrWhiteSpace(obfuscatedIps)) + { + error.ServerVariables["HTTP_X_FORWARDED_FOR"] = obfuscatedIps; + } + } } } } \ No newline at end of file diff --git a/src/NuGetGallery/App_Code/ViewHelpers.cshtml b/src/NuGetGallery/App_Code/ViewHelpers.cshtml index e86bd2b4bf..b15da2a79a 100644 --- a/src/NuGetGallery/App_Code/ViewHelpers.cshtml +++ b/src/NuGetGallery/App_Code/ViewHelpers.cshtml @@ -577,8 +577,8 @@ var hlp = new AccordionHelper(name, formModelStatePrefix, expanded, page); if (!disabled) { -
-