diff --git a/src/NzbDrone.Common/Instrumentation/CleanseLogMessage.cs b/src/NzbDrone.Common/Instrumentation/CleanseLogMessage.cs index 5be4e601d..6f0f25d71 100644 --- a/src/NzbDrone.Common/Instrumentation/CleanseLogMessage.cs +++ b/src/NzbDrone.Common/Instrumentation/CleanseLogMessage.cs @@ -1,4 +1,5 @@ -using System.Text.RegularExpressions; +using System.Linq; +using System.Text.RegularExpressions; namespace NzbDrone.Common.Instrumentation { @@ -10,7 +11,7 @@ public class CleanseLogMessage new Regex(@"(?<=\?|&)(apikey|token|passkey|uid)=(?[^&=]+?)(?= |&|$)", RegexOptions.Compiled | RegexOptions.IgnoreCase), new Regex(@"(?<=\?|&)[^=]*?(username|password)=(?[^&=]+?)(?= |&|$)", RegexOptions.Compiled | RegexOptions.IgnoreCase), new Regex(@"torrentleech\.org/(?[0-9a-z]+)", RegexOptions.Compiled | RegexOptions.IgnoreCase), - new Regex(@"(?<=iptorrents.*?)(?<=\?|&|;)(u|tp)=(?[^&=;]+?)(?= |;|&|$)", RegexOptions.Compiled | RegexOptions.IgnoreCase), + new Regex(@"iptorrents\.com/[/a-z0-9?&;]*?(?:[?&;](u|tp)=(?[^&=;]+?))+(?= |;|&|$)", RegexOptions.Compiled | RegexOptions.IgnoreCase), // Path new Regex(@"""C:\\Users\\(?[^\""]+?)(\\|$)", RegexOptions.Compiled | RegexOptions.IgnoreCase), @@ -32,8 +33,6 @@ public class CleanseLogMessage new Regex(@"(?<=\?|&)(authkey|torrent_pass)=(?[^&=]+?)(?=""|&|$)", RegexOptions.Compiled | RegexOptions.IgnoreCase) }; - //private static readonly Regex CleansingRegex = new Regex(@"(?<=apikey=)(\w+?)(?=\W|$|_)", RegexOptions.Compiled | RegexOptions.IgnoreCase); - public static string Cleanse(string message) { if (message.IsNullOrWhiteSpace()) @@ -43,7 +42,16 @@ public static string Cleanse(string message) foreach (var regex in CleansingRules) { - message = regex.Replace(message, m => m.Value.Replace(m.Groups["secret"].Index - m.Index, m.Groups["secret"].Length, "")); + message = regex.Replace(message, m => + { + var value = m.Value; + foreach (var capture in m.Groups["secret"].Captures.OfType().Reverse()) + { + value = value.Replace(capture.Index - m.Index, capture.Length, ""); + } + + return value; + }); } return message;