Skip to content

Commit

Permalink
Merge branch 'main' into map-aws-id-to-account-id
Browse files Browse the repository at this point in the history
  • Loading branch information
joeleonjr authored Nov 3, 2023
2 parents 7eb4b76 + 600903f commit 2073542
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 258 deletions.
36 changes: 15 additions & 21 deletions pkg/detectors/falsepositives.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math"
"strings"
"unicode"
"unicode/utf8"
)

var DefaultFalsePositives = []FalsePositive{"example", "xxxxxx", "aaaaaa", "abcde", "00000", "sample", "www"}
Expand All @@ -21,9 +22,9 @@ var wordList []byte
var programmingBookWords []byte

type Wordlists struct {
wordList []string
badList []string
programmingBookWords []string
wordList map[string]struct{}
badList map[string]struct{}
programmingBookWords map[string]struct{}
}

var FalsePositiveWordlists = Wordlists{
Expand All @@ -36,36 +37,29 @@ var FalsePositiveWordlists = Wordlists{
// Currently that includes: No number, english word in key, or matches common example pattens.
// Only the secret key material should be passed into this function
func IsKnownFalsePositive(match string, falsePositives []FalsePositive, wordCheck bool) bool {

if !utf8.ValidString(match) {
return true
}
lower := strings.ToLower(match)
for _, fp := range falsePositives {
if strings.Contains(strings.ToLower(match), string(fp)) {
if strings.Contains(lower, string(fp)) {
return true
}
}

if wordCheck {
// check against common substring badlist
if hasDictWord(FalsePositiveWordlists.badList, match) {
if _, ok := FalsePositiveWordlists.badList[lower]; ok {
return true
}

// check for dictionary word substrings
if hasDictWord(FalsePositiveWordlists.wordList, match) {
if _, ok := FalsePositiveWordlists.wordList[lower]; ok {
return true
}

// check for programming book token substrings
if hasDictWord(FalsePositiveWordlists.programmingBookWords, match) {
return true
}
}
return false
}

func hasDictWord(wordList []string, token string) bool {
lower := strings.ToLower(token)
for _, word := range wordList {
if strings.Contains(lower, word) {
if _, ok := FalsePositiveWordlists.programmingBookWords[lower]; ok {
return true
}
}
Expand All @@ -82,11 +76,11 @@ func HasDigit(key string) bool {
return false
}

func bytesToCleanWordList(data []byte) []string {
words := []string{}
func bytesToCleanWordList(data []byte) map[string]struct{} {
words := make(map[string]struct{})
for _, word := range strings.Split(string(data), "\n") {
if strings.TrimSpace(word) != "" {
words = append(words, strings.TrimSpace(strings.ToLower(word)))
words[strings.TrimSpace(strings.ToLower(word))] = struct{}{}
}
}
return words
Expand Down
7 changes: 7 additions & 0 deletions pkg/detectors/falsepositives_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,10 @@ func TestStringShannonEntropy(t *testing.T) {
})
}
}

func BenchmarkDefaultIsKnownFalsePositive(b *testing.B) {
for i := 0; i < b.N; i++ {
// Use a string that won't be found in any dictionary for the worst case check.
IsKnownFalsePositive("aoeuaoeuaoeuaoeuaoeuaoeu", DefaultFalsePositives, true)
}
}
89 changes: 0 additions & 89 deletions pkg/detectors/scrapersite/scrapersite.go

This file was deleted.

120 changes: 0 additions & 120 deletions pkg/detectors/scrapersite/scrapersite_test.go

This file was deleted.

2 changes: 0 additions & 2 deletions pkg/engine/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ import (
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/scrapeowl"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/scraperapi"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/scraperbox"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/scrapersite"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/scrapestack"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/scrapfly"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/scrapingant"
Expand Down Expand Up @@ -1315,7 +1314,6 @@ func DefaultDetectors() []detectors.Detector {
zenkitapi.Scanner{},
sherpadesk.Scanner{},
shotstack.Scanner{},
scrapersite.Scanner{},
luno.Scanner{},
apacta.Scanner{},
fmfw.Scanner{},
Expand Down
51 changes: 26 additions & 25 deletions pkg/pb/detectorspb/detectors.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/detectors.proto
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ enum DetectorType {
Meistertask = 656;
Mindmeister = 657;
PeopleDataLabs = 658;
ScraperSite = 659;
ScraperSite = 659 [deprecated = true];
Scrapfly = 660;
SimplyNoted = 661;
TravelPayouts = 662;
Expand Down

0 comments on commit 2073542

Please sign in to comment.