Skip to content

Commit

Permalink
fix(detect): extra secret from group before checking allowlist (#1152)
Browse files Browse the repository at this point in the history
  • Loading branch information
rgmz committed Apr 19, 2023
1 parent 81cf308 commit 51ca0f8
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions detect/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down

0 comments on commit 51ca0f8

Please sign in to comment.