Loading common/safelog/log.go +6 −3 Original line number Diff line number Diff line Loading @@ -10,10 +10,13 @@ import ( ) const ipv4Address = `\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}` const ipv6Address = `(([0-9a-fA-F]{0,4}:){2,7}([0-9a-fA-F]{0,4})?(` + ipv4Address + `))` + `|(([0-9a-fA-F]{0,4}:){2,7}([0-9a-fA-F]{0,4})?)` const ipv6Address = `([0-9a-fA-F]{0,4}:){5,7}([0-9a-fA-F]{0,4})?` const ipv6Compressed = `([0-9a-fA-F]{0,4}:){0,5}([0-9a-fA-F]{0,4})?(::)([0-9a-fA-F]{0,4}:){0,5}([0-9a-fA-F]{0,4})?` const ipv6Full = `(` + ipv6Address + `(` + ipv4Address + `))` + `|(` + ipv6Compressed + `(` + ipv4Address + `))` + `|(` + ipv6Address + `)` + `|(` + ipv6Compressed + `)` const optionalPort = `(:\d{1,5})?` const addressPattern = `((` + ipv4Address + `)|(\[(` + ipv6Address + `)\])|(` + ipv6Address + `))` + optionalPort const addressPattern = `((` + ipv4Address + `)|(\[(` + ipv6Full + `)\])|(` + ipv6Full + `))` + optionalPort const fullAddrPattern = `(^|\s|[^\w:])` + addressPattern + `(\s|(:\s)|[^\w:]|$)` var scrubberPatterns = []*regexp.Regexp{ Loading common/safelog/log_test.go +8 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,11 @@ func TestLogScrubberMessages(t *testing.T) { "(1:2:3:4:c:d:e:f) {1:2:3:4:c:d:e:f}", "([scrubbed]) {[scrubbed]}\n", }, { //Make sure it doesn't scrub timestamps "2019/05/08 15:37:31 starting", "2019/05/08 15:37:31 starting\n", }, } { var buff bytes.Buffer log.SetFlags(0) //remove all extra log output for test comparisons Loading Loading @@ -102,9 +107,12 @@ func TestLogScrubberGoodFormats(t *testing.T) { "[1:2:3:4:c:d:e:f]:55", "[1111:2222:3333:4444:CCCC:DDDD:EEEE:FFFF]:65535", // compressed IPv6 "::f", "::d:e:f", "1:2:3::", "1:2:3::d:e:f", "1:2:3:d:e:f::", "::1:2:3:d:e:f", "1111:2222:3333::DDDD:EEEE:FFFF", // compressed IPv6 with brackets "[::d:e:f]", Loading Loading
common/safelog/log.go +6 −3 Original line number Diff line number Diff line Loading @@ -10,10 +10,13 @@ import ( ) const ipv4Address = `\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}` const ipv6Address = `(([0-9a-fA-F]{0,4}:){2,7}([0-9a-fA-F]{0,4})?(` + ipv4Address + `))` + `|(([0-9a-fA-F]{0,4}:){2,7}([0-9a-fA-F]{0,4})?)` const ipv6Address = `([0-9a-fA-F]{0,4}:){5,7}([0-9a-fA-F]{0,4})?` const ipv6Compressed = `([0-9a-fA-F]{0,4}:){0,5}([0-9a-fA-F]{0,4})?(::)([0-9a-fA-F]{0,4}:){0,5}([0-9a-fA-F]{0,4})?` const ipv6Full = `(` + ipv6Address + `(` + ipv4Address + `))` + `|(` + ipv6Compressed + `(` + ipv4Address + `))` + `|(` + ipv6Address + `)` + `|(` + ipv6Compressed + `)` const optionalPort = `(:\d{1,5})?` const addressPattern = `((` + ipv4Address + `)|(\[(` + ipv6Address + `)\])|(` + ipv6Address + `))` + optionalPort const addressPattern = `((` + ipv4Address + `)|(\[(` + ipv6Full + `)\])|(` + ipv6Full + `))` + optionalPort const fullAddrPattern = `(^|\s|[^\w:])` + addressPattern + `(\s|(:\s)|[^\w:]|$)` var scrubberPatterns = []*regexp.Regexp{ Loading
common/safelog/log_test.go +8 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,11 @@ func TestLogScrubberMessages(t *testing.T) { "(1:2:3:4:c:d:e:f) {1:2:3:4:c:d:e:f}", "([scrubbed]) {[scrubbed]}\n", }, { //Make sure it doesn't scrub timestamps "2019/05/08 15:37:31 starting", "2019/05/08 15:37:31 starting\n", }, } { var buff bytes.Buffer log.SetFlags(0) //remove all extra log output for test comparisons Loading Loading @@ -102,9 +107,12 @@ func TestLogScrubberGoodFormats(t *testing.T) { "[1:2:3:4:c:d:e:f]:55", "[1111:2222:3333:4444:CCCC:DDDD:EEEE:FFFF]:65535", // compressed IPv6 "::f", "::d:e:f", "1:2:3::", "1:2:3::d:e:f", "1:2:3:d:e:f::", "::1:2:3:d:e:f", "1111:2222:3333::DDDD:EEEE:FFFF", // compressed IPv6 with brackets "[::d:e:f]", Loading