Skip to content

Commit a2592ce

Browse files
committed
[CWS] add jwt as default sensitive word
1 parent 21276c4 commit a2592ce

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

pkg/security/utils/scrubber.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
)
1717

1818
var (
19-
additionals = []string{"*token*"}
19+
additionals = []string{"*token*", "*jwt*"}
2020
)
2121

2222
// Scrubber is a struct that holds the proc scrubber and the regex scrubber

pkg/security/utils/scrubber_test.go

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,45 @@ import (
1313
)
1414

1515
func TestScrubber(t *testing.T) {
16-
t.Run("cmdline", func(t *testing.T) {
17-
scrubber, err := NewScrubber([]string{"token"}, []string{"t[a-z]*n", "t.st"})
16+
t.Run("cmdline-default", func(t *testing.T) {
17+
scrubber, err := NewScrubber(nil, nil)
1818
assert.NoError(t, err)
1919
assert.NotNil(t, scrubber)
2020

21-
scrubbed := scrubber.ScrubCommand([]string{"--token 1234567890 --test 1234567890"})
21+
scrubbed := scrubber.ScrubCommand([]string{"cmd --secret 1234567890 --token 1234567890 --jwt abc"})
22+
assert.Equal(t, []string{"cmd", "--secret", "********", "--token", "********", "--jwt", "********"}, scrubbed)
23+
24+
scrubbed = scrubber.ScrubCommand([]string{"cmd", "--secret", "1234567890", "--token", "1234567890", "--jwt", "abc"})
25+
assert.Equal(t, []string{"cmd", "--secret", "********", "--token", "********", "--jwt", "********"}, scrubbed)
26+
})
27+
28+
t.Run("cmdline-custom-word", func(t *testing.T) {
29+
scrubber, err := NewScrubber([]string{"custom"}, nil)
30+
assert.NoError(t, err)
31+
assert.NotNil(t, scrubber)
32+
33+
scrubbed := scrubber.ScrubCommand([]string{"cmd --secret 1234567890 --token 1234567890 --custom abc"})
34+
assert.Equal(t, []string{"cmd", "--secret", "********", "--token", "********", "--custom", "********"}, scrubbed)
35+
36+
scrubbed = scrubber.ScrubCommand([]string{"cmd", "--secret", "1234567890", "--token", "1234567890", "--custom", "abc"})
37+
assert.Equal(t, []string{"cmd", "--secret", "********", "--token", "********", "--custom", "********"}, scrubbed)
38+
})
39+
40+
t.Run("cmdline-custom-regexp", func(t *testing.T) {
41+
scrubber, err := NewScrubber(nil, []string{"a[a-z]*c", "t.st"})
42+
assert.NoError(t, err)
43+
assert.NotNil(t, scrubber)
44+
45+
scrubbed := scrubber.ScrubCommand([]string{"--abc 1234567890 --test 1234567890"})
2246
assert.Equal(t, []string{"--***** 1234567890 --***** 1234567890"}, scrubbed)
2347
})
2448

25-
t.Run("line", func(t *testing.T) {
26-
scrubber, err := NewScrubber([]string{"token"}, []string{"t[a-z]*n", "t.st"})
49+
t.Run("line-custom-regexp", func(t *testing.T) {
50+
scrubber, err := NewScrubber(nil, []string{"a[a-z]*c", "t.st"})
2751
assert.NoError(t, err)
2852
assert.NotNil(t, scrubber)
2953

30-
scrubbed := scrubber.ScrubLine("token 1234567890 test 1234567890")
54+
scrubbed := scrubber.ScrubLine("abc 1234567890 test 1234567890")
3155
assert.Equal(t, "***** 1234567890 ***** 1234567890", scrubbed)
3256
})
3357
}

0 commit comments

Comments
 (0)