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
Centralize false positive removal in engine
  • Loading branch information
dustin-decker committed Mar 29, 2024
commit 03098bcb1f1d3221034870b686075b8bf8a19f9f
17 changes: 17 additions & 0 deletions pkg/detectors/falsepositives.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,20 @@ func FilterResultsWithEntropy(results []Result, entropy float64) []Result {
}
return filteredResults
}

// FilterKnownFalsePositives filters out known false positives from the results.
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)
}
}
}
return filteredResults
}
2 changes: 2 additions & 0 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,8 @@ func (e *Engine) detectChunk(ctx context.Context, data detectableChunk) {
results = detectors.CleanResults(results)
}

results = detectors.FilterKnownFalsePositives(results, detectors.DefaultFalsePositives, true)

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