mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-12-01 13:34:23 +01:00
fix(detect): extra secret from group before checking allowlist (#1152)
This commit is contained in:
1 parent
81cf30855c
commit
62aef54969
1 file changed
+11
-11
+11
-11
@@ -292,6 +292,17 @@ func (d *Detector) detectRule(fragment Fragment, rule config.Rule) []report.Find
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// extract secret from secret group if set
|
||||||
|
if rule.SecretGroup != 0 {
|
||||||
|
groups := rule.Regex.FindStringSubmatch(secret)
|
||||||
|
if len(groups) <= rule.SecretGroup || len(groups) == 0 {
|
||||||
|
// Config validation should prevent this
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
secret = groups[rule.SecretGroup]
|
||||||
|
finding.Secret = secret
|
||||||
|
}
|
||||||
|
|
||||||
// check if the regexTarget is defined in the allowlist "regexes" entry
|
// check if the regexTarget is defined in the allowlist "regexes" entry
|
||||||
allowlistTarget := finding.Secret
|
allowlistTarget := finding.Secret
|
||||||
switch rule.Allowlist.RegexTarget {
|
switch rule.Allowlist.RegexTarget {
|
||||||
@@ -313,17 +324,6 @@ func (d *Detector) detectRule(fragment Fragment, rule config.Rule) []report.Find
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// extract secret from secret group if set
|
|
||||||
if rule.SecretGroup != 0 {
|
|
||||||
groups := rule.Regex.FindStringSubmatch(secret)
|
|
||||||
if len(groups) <= rule.SecretGroup || len(groups) == 0 {
|
|
||||||
// Config validation should prevent this
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
secret = groups[rule.SecretGroup]
|
|
||||||
finding.Secret = secret
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if the secret is in the list of stopwords
|
// check if the secret is in the list of stopwords
|
||||||
if rule.Allowlist.ContainsStopWord(finding.Secret) ||
|
if rule.Allowlist.ContainsStopWord(finding.Secret) ||
|
||||||
d.Config.Allowlist.ContainsStopWord(finding.Secret) {
|
d.Config.Allowlist.ContainsStopWord(finding.Secret) {
|
||||||
|
|||||||
Reference in new issue
Block a user