mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 16:59:12 +00:00
feat(logs): webhook sanitization (#809)
* feat: sanitize passwords from json payload * add webhook sanitization * update comments Co-authored-by: soup <soup@r4tio.dev> * sanitize RED apikeys from webhook payloads * added an optional whitespace token between field name and data --------- Co-authored-by: soup <soup@r4tio.dev>
This commit is contained in:
parent
69f6acbc4d
commit
169863dded
2 changed files with 18 additions and 2 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue