-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Changes from 1 commit
fd0e685
03098bc
55d030d
e2bf219
ff4bb0a
f9e3d74
3fce83e
211f183
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,15 +111,15 @@ | |
var filteredResults []Result | ||
for _, result := range results { | ||
if !result.Verified { | ||
if result.RawV2 != nil { | ||
if StringShannonEntropy(string(result.RawV2)) >= entropy { | ||
filteredResults = append(filteredResults, result) | ||
} | ||
} else { | ||
if result.Raw != nil { | ||
if StringShannonEntropy(string(result.Raw)) >= entropy { | ||
filteredResults = append(filteredResults, result) | ||
} | ||
} else { | ||
filteredResults = append(filteredResults, result) | ||
} | ||
} else { | ||
filteredResults = append(filteredResults, result) | ||
} | ||
} | ||
return filteredResults | ||
|
@@ -129,25 +129,26 @@ | |
func FilterKnownFalsePositives(results []Result, falsePositives []FalsePositive, wordCheck bool) []Result { | ||
var filteredResults []Result | ||
for _, result := range results { | ||
switch result.DetectorType { | ||
case detectorspb.DetectorType_CustomRegex: | ||
filteredResults = append(filteredResults, result) | ||
break | ||
case detectorspb.DetectorType_GCP: | ||
filteredResults = append(filteredResults, result) | ||
break | ||
default: | ||
if result.RawV2 != nil { | ||
if !IsKnownFalsePositive(string(result.RawV2), falsePositives, wordCheck) { | ||
filteredResults = append(filteredResults, result) | ||
} | ||
} else { | ||
if !IsKnownFalsePositive(string(result.Raw), falsePositives, wordCheck) { | ||
if !result.Verified { | ||
switch result.DetectorType { | ||
case detectorspb.DetectorType_CustomRegex: | ||
filteredResults = append(filteredResults, result) | ||
break | ||
case detectorspb.DetectorType_GCP: | ||
filteredResults = append(filteredResults, result) | ||
break | ||
default: | ||
if result.Raw != nil { | ||
if !IsKnownFalsePositive(string(result.Raw), falsePositives, wordCheck) { | ||
filteredResults = append(filteredResults, result) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think it would be useful to trace log that something was filtered? There have been a few times — most recently #2620 — where the cause of something not being detected wasn't immediately obvious, and required custom logging to see that the FP check was responsible. (Incidentally, there's a lot of noise from this specific log) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rgmz in internal discussions we've actually been leaning towards expanding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like that. It would be an intuitive expansion of the flag. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've extended the results flag with an additional |
||
} else { | ||
filteredResults = append(filteredResults, result) | ||
} | ||
} | ||
} else { | ||
filteredResults = append(filteredResults, result) | ||
} | ||
|
||
} | ||
return filteredResults | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we breaking for these detector types? My understanding is that the effect will be that when a custom regex (or gcp) detector returns multiple unverified results, we'll ignore all but the first one. Is that intended? And even if it is, is this function the place for it? (It doesn't sound like it has anything to do with false positives.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lint action is actually flagging this as a "redundant break" because it is breaking out of the
switch
, not thefor
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦 thanks for correcting me!