maintaining parity between current master

This commit is contained in:
Zach Rice committed 2022-03-11 17:55:50 -06:00
1 parent 6fed917106
commit c53e0fc98d
2 files changed
+30 -4

No files matched your search

+19 -4
View File
@@ -9,13 +9,13 @@ import (
"strings"
"sync"
"github.com/rs/zerolog/log"
"github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/detect/git"
"github.com/zricethezav/gitleaks/v8/report"
"github.com/fatih/semgroup"
"github.com/gitleaks/go-gitdiff/gitdiff"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
)
@@ -172,10 +172,25 @@ func (d *Detector) detectRule(fragment Fragment, rule *config.Rule) []report.Fin
// check entropy
entropy := shannonEntropy(finding.Secret)
finding.Entropy = float32(entropy)
if rule.EntropySet() && entropy <= rule.Entropy {
// entropy is too low, skip this finding
continue
if rule.EntropySet() {
if entropy <= rule.Entropy {
// entropy is too low, skip this finding
continue
}
// NOTE: this is a goofy hack to get around the fact there golang's regex engine
// does not support positive lookaheads. Ideally we would want to add a
// restriction on generic rules regex that requires the secret match group
// contains both numbers and alphabetical characters. What this bit of code does is
// check if the ruleid is prepended with "generic" and enforces the
// secret contains both digits and alphabetical characters.
// TODO: this should be replaced with stop words
if strings.HasPrefix(rule.RuleID, "generic") {
if !containsDigit(secret) {
continue
}
}
}
findings = append(findings, finding)
}
return findings
+11
View File
@@ -94,3 +94,14 @@ func printFinding(f report.Finding) {
b, _ = json.MarshalIndent(f, "", " ")
fmt.Println(string(b))
}
func containsDigit(s string) bool {
for _, c := range s {
switch c {
case '1', '2', '3', '4', '5', '6', '7', '8', '9':
return true
}
}
return false
}