From 9ca291ecaf2eb0232424f7a632a385284b126e27 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Tue, 2 Jun 2020 20:54:22 +0200 Subject: [PATCH] Cleanse remote IP Address from trace log file --- .../CleanseLogMessageFixture.cs | 21 +++++++++++++++ .../Instrumentation/CleanseLogMessage.cs | 26 ++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Common.Test/InstrumentationTests/CleanseLogMessageFixture.cs b/src/NzbDrone.Common.Test/InstrumentationTests/CleanseLogMessageFixture.cs index 8a61ef050..2c58f5dba 100644 --- a/src/NzbDrone.Common.Test/InstrumentationTests/CleanseLogMessageFixture.cs +++ b/src/NzbDrone.Common.Test/InstrumentationTests/CleanseLogMessageFixture.cs @@ -57,5 +57,26 @@ namespace NzbDrone.Common.Test.InstrumentationTests cleansedMessage.Should().NotContain("mySecret"); cleansedMessage.Should().NotContain("01233210"); } + + [TestCase(@"Some message (from 32.2.3.5 user agent)")] + [TestCase(@"Auth-Invalidated ip 32.2.3.5")] + [TestCase(@"Auth-Success ip 32.2.3.5")] + [TestCase(@"Auth-Logout ip 32.2.3.5")] + public void should_clean_ipaddress(string message) + { + var cleansedMessage = CleanseLogMessage.Cleanse(message); + + cleansedMessage.Should().NotContain(".2.3."); + } + + [TestCase(@"Some message (from 10.2.3.2 user agent)")] + [TestCase(@"Auth-Unauthorized ip 32.2.3.5")] + [TestCase(@"Auth-Failure ip 32.2.3.5")] + public void should_not_clean_ipaddress(string message) + { + var cleansedMessage = CleanseLogMessage.Cleanse(message); + + cleansedMessage.Should().Be(message); + } } } diff --git a/src/NzbDrone.Common/Instrumentation/CleanseLogMessage.cs b/src/NzbDrone.Common/Instrumentation/CleanseLogMessage.cs index 9bcf18994..02dc07647 100644 --- a/src/NzbDrone.Common/Instrumentation/CleanseLogMessage.cs +++ b/src/NzbDrone.Common/Instrumentation/CleanseLogMessage.cs @@ -1,4 +1,6 @@ -using System.Linq; +using System; +using System.Linq; +using System.Net; using System.Text.RegularExpressions; using NzbDrone.Common.Extensions; @@ -41,6 +43,8 @@ namespace NzbDrone.Common.Instrumentation new Regex(@"(?<=\?|&)(authkey|torrent_pass)=(?[^&=]+?)(?=""|&|$)", RegexOptions.Compiled | RegexOptions.IgnoreCase) }; + private static readonly Regex CleanseRemoteIPRegex = new Regex(@"(?:Auth-\w+(?