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:
Zachary Rice authored and GitHub committed 2021-12-02 20:04:36 -06:00
1 parent 9358e84588
commit 98d5648f6e
22 files changed
+248 -107

No files matched your search

+10 -16
View File
@@ -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
}