mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-12-01 13:34:23 +01:00
maintaining parity between current master
This commit is contained in:
1 parent
6fed917106
commit
c53e0fc98d
2 files changed
+28
-2
No files matched your search
+17
-2
@@ -9,13 +9,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
"github.com/zricethezav/gitleaks/v8/config"
|
"github.com/zricethezav/gitleaks/v8/config"
|
||||||
"github.com/zricethezav/gitleaks/v8/detect/git"
|
"github.com/zricethezav/gitleaks/v8/detect/git"
|
||||||
"github.com/zricethezav/gitleaks/v8/report"
|
"github.com/zricethezav/gitleaks/v8/report"
|
||||||
|
|
||||||
"github.com/fatih/semgroup"
|
"github.com/fatih/semgroup"
|
||||||
"github.com/gitleaks/go-gitdiff/gitdiff"
|
"github.com/gitleaks/go-gitdiff/gitdiff"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -172,10 +172,25 @@ func (d *Detector) detectRule(fragment Fragment, rule *config.Rule) []report.Fin
|
|||||||
// check entropy
|
// check entropy
|
||||||
entropy := shannonEntropy(finding.Secret)
|
entropy := shannonEntropy(finding.Secret)
|
||||||
finding.Entropy = float32(entropy)
|
finding.Entropy = float32(entropy)
|
||||||
if rule.EntropySet() && entropy <= rule.Entropy {
|
if rule.EntropySet() {
|
||||||
|
if entropy <= rule.Entropy {
|
||||||
// entropy is too low, skip this finding
|
// entropy is too low, skip this finding
|
||||||
continue
|
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)
|
findings = append(findings, finding)
|
||||||
}
|
}
|
||||||
return findings
|
return findings
|
||||||
|
|||||||
@@ -94,3 +94,14 @@ func printFinding(f report.Finding) {
|
|||||||
b, _ = json.MarshalIndent(f, "", " ")
|
b, _ = json.MarshalIndent(f, "", " ")
|
||||||
fmt.Println(string(b))
|
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
|
||||||
|
}
|
||||||
Reference in new issue
Block a user