From 51ca0f89b915509f07f956144ce2c64994b80947 Mon Sep 17 00:00:00 2001 From: Richard Gomez <32133502+rgmz@users.noreply.github.com> Date: Wed, 19 Apr 2023 12:57:24 -0400 Subject: [PATCH] fix(detect): extra secret from group before checking allowlist (#1152) --- detect/detect.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/detect/detect.go b/detect/detect.go index f170bb0d..0068d277 100644 --- a/detect/detect.go +++ b/detect/detect.go @@ -292,6 +292,17 @@ func (d *Detector) detectRule(fragment Fragment, rule config.Rule) []report.Find 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 allowlistTarget := finding.Secret switch rule.Allowlist.RegexTarget { @@ -313,17 +324,6 @@ func (d *Detector) detectRule(fragment Fragment, rule config.Rule) []report.Find 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 if rule.Allowlist.ContainsStopWord(finding.Secret) || d.Config.Allowlist.ContainsStopWord(finding.Secret) {