Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move detectors.IsKnownFalsePositive from the detectors and into the engine #2643

Merged
merged 8 commits into from
Apr 22, 2024
Prev Previous commit
Next Next commit
update excludes
  • Loading branch information
dustin-decker committed Mar 29, 2024
commit f9e3d743e452995294c9da21409a1af4f1a000f7
25 changes: 18 additions & 7 deletions pkg/detectors/falsepositives.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"unicode/utf8"

ahocorasick "github.com/BobuSumisu/aho-corasick"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
)

var DefaultFalsePositives = []FalsePositive{"example", "xxxxxx", "aaaaaa", "abcde", "00000", "sample", "www"}
Expand Down Expand Up @@ -128,15 +129,25 @@
func FilterKnownFalsePositives(results []Result, falsePositives []FalsePositive, wordCheck bool) []Result {
var filteredResults []Result
for _, result := range results {
if result.RawV2 != nil {
if !IsKnownFalsePositive(string(result.RawV2), falsePositives, wordCheck) {
filteredResults = append(filteredResults, result)
}
} else {
if !IsKnownFalsePositive(string(result.Raw), falsePositives, wordCheck) {
filteredResults = append(filteredResults, result)
switch result.DetectorType {
case detectorspb.DetectorType_CustomRegex:
filteredResults = append(filteredResults, result)
break

Check failure on line 135 in pkg/detectors/falsepositives.go

View workflow job for this annotation

GitHub Actions / golangci-lint

S1023: redundant break statement (gosimple)
case detectorspb.DetectorType_GCP:
filteredResults = append(filteredResults, result)
break

Check failure on line 138 in pkg/detectors/falsepositives.go

View workflow job for this annotation

GitHub Actions / golangci-lint

S1023: redundant break statement (gosimple)
default:
if result.RawV2 != nil {
if !IsKnownFalsePositive(string(result.RawV2), falsePositives, wordCheck) {
filteredResults = append(filteredResults, result)
}
} else {
if !IsKnownFalsePositive(string(result.Raw), falsePositives, wordCheck) {
filteredResults = append(filteredResults, result)
}
}
}

}
return filteredResults
}
4 changes: 1 addition & 3 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -827,9 +827,7 @@ func (e *Engine) detectChunk(ctx context.Context, data detectableChunk) {
results = detectors.CleanResults(results)
}

if data.detector.Type() != detectorspb.DetectorType_CustomRegex {
results = detectors.FilterKnownFalsePositives(results, detectors.DefaultFalsePositives, true)
}
results = detectors.FilterKnownFalsePositives(results, detectors.DefaultFalsePositives, true)

if e.filterEntropy != nil {
results = detectors.FilterResultsWithEntropy(results, *e.filterEntropy)
Expand Down
Loading