diff --git a/internal/http/logs.go b/internal/http/logs.go index 335d15c..8305cd7 100644 --- a/internal/http/logs.go +++ b/internal/http/logs.go @@ -94,6 +94,10 @@ var ( pattern *regexp.Regexp repl string }{ + { + pattern: regexp.MustCompile(`("apikey\\":\s?\\"|"host\\":\s?\\"|"password\\":\s?\\"|"user\\":\s?\\"|ExternalWebhookHost:)(\S+)(\\"|\sExternalWebhookData:)`), + repl: "${1}REDACTED${3}", + }, { pattern: regexp.MustCompile(`(torrent_pass|passkey|authkey|auth|secret_key|api|apikey)=([a-zA-Z0-9]+)`), repl: "${1}=REDACTED", @@ -166,9 +170,9 @@ func SanitizeLogFile(filePath string, output io.Writer) error { strings.Contains(line, `"module":"action"`) for i := 0; i < len(regexReplacements); i++ { - // Apply the first two patterns only if the line contains "module":"feed", + // Apply the first three patterns only if the line contains "module":"feed", // "module":"filter", "repo":"release", or "module":"action" - if i < 2 { + if i < 3 { if bFilter { line = regexReplacements[i].pattern.ReplaceAllString(line, regexReplacements[i].repl) } diff --git a/internal/http/logs_sanitize_test.go b/internal/http/logs_sanitize_test.go index 8b9c9c7..1f1c780 100644 --- a/internal/http/logs_sanitize_test.go +++ b/internal/http/logs_sanitize_test.go @@ -138,6 +138,18 @@ func TestSanitizeLogFile(t *testing.T) { input: "\"module\":\"irc\" PRIVMSG NickServ IDENTIFY zAPEJEA8ryYnpj3AiE3KJ", expected: "\"module\":\"irc\" PRIVMSG NickServ IDENTIFY REDACTED", }, + { + input: "\"module\":\"action\" \\\"host\\\":\\\"subdomain.domain.com:42069/subfolder\\\", \\n \\\"user\\\":\\\"AUserName\\\", \\n \\\"password\\\":\\\"p4ssw0!rd\\\", \\n", + expected: "\"module\":\"action\" \\\"host\\\":\\\"REDACTED\\\", \\n \\\"user\\\":\\\"REDACTED\\\", \\n \\\"password\\\":\\\"REDACTED\\\", \\n", + }, + { + input: "\"module\":\"action\" ExternalWebhookHost:http://127.0.0.1:6940/api/upgrade ExternalWebhookData:", + expected: "\"module\":\"action\" ExternalWebhookHost:REDACTED ExternalWebhookData:", + }, + { + input: "\"module\":\"filter\" \\\"id\\\": 3855,\\n \\\"apikey\\\": \\\"ad789a9s8d.asdpoiasdpojads09sad809\\\",\\n \\\"minratio\\\": 10.0\\n", + expected: "\"module\":\"filter\" \\\"id\\\": 3855,\\n \\\"apikey\\\": \\\"REDACTED\\\",\\n \\\"minratio\\\": 10.0\\n", + }, } for _, testCase := range testCases {