mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-12-01 05:24:22 +01:00
feat(config): update rule validation (#1466)
This commit is contained in:
1 parent
6dfcf5e949
commit
1aae66d564
4 files changed
+64
-26
No files matched your search
+5
-10
@@ -2,7 +2,6 @@ package config
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -82,10 +81,6 @@ func (vc *ViperConfig) Translate() (Config, error) {
|
||||
rulesMap := make(map[string]Rule)
|
||||
|
||||
for _, r := range vc.Rules {
|
||||
if strings.TrimSpace(r.ID) == "" {
|
||||
return Config{}, fmt.Errorf("rule ID is missing or empty, regex: %s", r.Regex)
|
||||
}
|
||||
|
||||
var allowlistRegexes []*regexp.Regexp
|
||||
for _, a := range r.Allowlist.Regexes {
|
||||
allowlistRegexes = append(allowlistRegexes, regexp.MustCompile(a))
|
||||
@@ -120,8 +115,8 @@ func (vc *ViperConfig) Translate() (Config, error) {
|
||||
configPathRegex = regexp.MustCompile(r.Path)
|
||||
}
|
||||
r := Rule{
|
||||
Description: r.Description,
|
||||
RuleID: r.ID,
|
||||
Description: r.Description,
|
||||
Regex: configRegex,
|
||||
Path: configPathRegex,
|
||||
SecretGroup: r.SecretGroup,
|
||||
@@ -136,11 +131,11 @@ func (vc *ViperConfig) Translate() (Config, error) {
|
||||
StopWords: r.Allowlist.StopWords,
|
||||
},
|
||||
}
|
||||
orderedRules = append(orderedRules, r.RuleID)
|
||||
|
||||
if r.Regex != nil && r.SecretGroup > r.Regex.NumSubexp() {
|
||||
return Config{}, fmt.Errorf("%s: invalid regex secret group %d, max regex secret group %d", r.RuleID, r.SecretGroup, r.Regex.NumSubexp())
|
||||
if err := r.Validate(); err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
|
||||
orderedRules = append(orderedRules, r.RuleID)
|
||||
rulesMap[r.RuleID] = r
|
||||
}
|
||||
var allowlistRegexes []*regexp.Regexp
|
||||
|
||||
Reference in new issue
Block a user