fix_: correct sensitive regex (#6188)

This commit is contained in:
frank 2024-12-17 03:58:15 +08:00 committed by GitHub
parent 08eee8a647
commit 75bdda2712
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View File

@ -37,7 +37,7 @@ var sensitiveKeys = []string{
"gifs/api-key",
}
var sensitiveRegexString = fmt.Sprintf(`(?i)(".*?(%s).*?")\s*:\s*("[^"]*")`, strings.Join(sensitiveKeys, "|"))
var sensitiveRegexString = fmt.Sprintf(`(?i)("\w*?(%s)\w*?")\s*:\s*(".*?")`, strings.Join(sensitiveKeys, "|"))
var sensitiveRegex = regexp.MustCompile(sensitiveRegexString)

View File

@ -49,6 +49,11 @@ func TestRemoveSensitiveInfo(t *testing.T) {
input: `{"username":"user1","email":"user1@example.com"}`,
expected: `{"username":"user1","email":"user1@example.com"}`,
},
{
name: "should not match password substring in field names",
input: `{"eventValue":{"flowType":"UserProfileCreatePassword","viewId":"UserProfileCreatePassword"}}`,
expected: `{"eventValue":{"flowType":"UserProfileCreatePassword","viewId":"UserProfileCreatePassword"}}`,
},
}
for _, tc := range testCases {