Skip to content

Commit

Permalink
fix(log): add brackets to secret mask (#333)
Browse files Browse the repository at this point in the history
Co-authored-by: dave vader <[email protected]>
  • Loading branch information
ecrupper and plyr4 committed Nov 8, 2023
1 parent 94c29db commit e7d5019
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (l *Log) MaskData(secrets []string) {
// create regexp to match secrets in the log data surrounded by regexp metacharacters
//
// https://pkg.go.dev/regexp#MustCompile
buffer := `(\s|^|=|"|\?|:|'|\.|,|&|$|;)`
buffer := `(\s|^|=|"|\?|:|'|\.|,|&|$|;|\[|\])`
re := regexp.MustCompile((buffer + escaped + buffer))

// create a mask for the secret
Expand Down
7 changes: 7 additions & 0 deletions library/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ func TestLibrary_Log_MaskData(t *testing.T) {
s4Masked := "SOME_SECRET=***"
s5 := "www.example.com?username=secret&password=extrasecret"
s5Masked := "www.example.com?username=***&password=***"
s6 := "[token: extrasecret]"
s6Masked := "[token: ***]"

tests := []struct {
want []byte
Expand Down Expand Up @@ -85,6 +87,11 @@ func TestLibrary_Log_MaskData(t *testing.T) {
log: []byte(s5),
secrets: sVals,
},
{ // secret in verbose brackets
want: []byte(s6Masked),
log: []byte(s6),
secrets: sVals,
},
{ // empty secrets slice
want: []byte(s3),
log: []byte(s3),
Expand Down

0 comments on commit e7d5019

Please sign in to comment.