mirror of
https://github.com/trufflesecurity/trufflehog.git
synced 2024-11-10 07:04:24 +00:00
strings contain keyword check, add collection name to keywords (#2602)
This commit is contained in:
parent
3f47dbccfb
commit
1216fa23c9
2 changed files with 11 additions and 1 deletions
|
@ -60,8 +60,18 @@ func (s *Source) addKeywords(keywords []string) {
|
|||
}
|
||||
|
||||
func (s *Source) addKeyword(keyword string) {
|
||||
// fast check
|
||||
if _, ok := s.DetectorKeywords[keyword]; ok {
|
||||
s.keywords[keyword] = struct{}{}
|
||||
return
|
||||
}
|
||||
|
||||
// slow check. This is to handle the case where the keyword is a substring of a detector keyword
|
||||
// e.g. "datadog-token" is a variable key in postman, but "datadog" is a detector keyword
|
||||
for k := range s.DetectorKeywords {
|
||||
if strings.Contains(keyword, k) {
|
||||
s.keywords[k] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -325,6 +335,7 @@ func (s *Source) scanCollection(ctx context.Context, chunksChan chan *sources.Ch
|
|||
ctx.Logger().V(2).Info("starting scanning collection", collection.Info.Name, "uuid", collection.Info.UID)
|
||||
metadata.CollectionInfo = collection.Info
|
||||
metadata.Type = COLLECTION_TYPE
|
||||
s.addKeyword(collection.Info.Name)
|
||||
|
||||
if !metadata.fromLocal {
|
||||
metadata.FullID = metadata.CollectionInfo.UID
|
||||
|
|
|
@ -145,7 +145,6 @@ func TestSource_FormatAndInjectKeywords(t *testing.T) {
|
|||
expected := strings.Split(tc.expected, "\n")
|
||||
sort.Strings(got)
|
||||
sort.Strings(expected)
|
||||
// CHATGPT CHECK HERE
|
||||
|
||||
if !reflect.DeepEqual(got, expected) {
|
||||
t.Errorf("Expected result: %q, got: %q", tc.expected, result)
|
||||
|
|
Loading…
Reference in a new issue