mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-30 21:24:21 +01:00
introducing secretGroup, the best group (#734)
* working on deduping * my eyes... oh god my poor eyes * more readme * more readme * more readme * more readme and formatting
This commit is contained in:
1 parent
9358e84588
commit
98d5648f6e
22 files changed
+248
-107
No files matched your search
+10
-16
@@ -6,23 +6,17 @@ import (
|
||||
)
|
||||
|
||||
type Rule struct {
|
||||
Description string
|
||||
RuleID string
|
||||
Entropy float64
|
||||
EntropyReGroup int
|
||||
Regex *regexp.Regexp
|
||||
Path *regexp.Regexp
|
||||
Tags []string
|
||||
Allowlist Allowlist
|
||||
Description string
|
||||
RuleID string
|
||||
Entropy float64
|
||||
SecretGroup int
|
||||
Regex *regexp.Regexp
|
||||
Path *regexp.Regexp
|
||||
Tags []string
|
||||
Allowlist Allowlist
|
||||
}
|
||||
|
||||
func (r *Rule) IncludeEntropy(secret string) (bool, float64) {
|
||||
groups := r.Regex.FindStringSubmatch(secret)
|
||||
if len(groups)-1 > r.EntropyReGroup || len(groups) == 0 {
|
||||
// Config validation should prevent this
|
||||
return false, 0.0
|
||||
}
|
||||
|
||||
// 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
|
||||
@@ -30,12 +24,12 @@ func (r *Rule) IncludeEntropy(secret string) (bool, float64) {
|
||||
// check if the ruleid is prepended with "generic" and enforces the
|
||||
// secret contains both digits and alphabetical characters.
|
||||
if strings.HasPrefix(r.RuleID, "generic") {
|
||||
if !containsDigit(groups[r.EntropyReGroup]) {
|
||||
if !containsDigit(secret) {
|
||||
return false, 0.0
|
||||
}
|
||||
}
|
||||
// group = 0 will check the entropy of the whole regex match
|
||||
e := shannonEntropy(groups[r.EntropyReGroup])
|
||||
e := shannonEntropy(secret)
|
||||
if e > r.Entropy {
|
||||
return true, e
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user