|
@@ -26,6 +26,7 @@ type Rule struct {
|
|
|
tags []string
|
|
tags []string
|
|
|
entropies []*entropyRange
|
|
entropies []*entropyRange
|
|
|
entropyROI string
|
|
entropyROI string
|
|
|
|
|
+ fileTypes []*regexp.Regexp
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// TomlConfig is used for loading gitleaks configs from a toml file
|
|
// TomlConfig is used for loading gitleaks configs from a toml file
|
|
@@ -37,6 +38,7 @@ type TomlConfig struct {
|
|
|
Tags []string
|
|
Tags []string
|
|
|
Severity string
|
|
Severity string
|
|
|
EntropyROI string
|
|
EntropyROI string
|
|
|
|
|
+ FileTypes []string
|
|
|
}
|
|
}
|
|
|
Whitelist struct {
|
|
Whitelist struct {
|
|
|
Files []string
|
|
Files []string
|
|
@@ -55,7 +57,8 @@ type Config struct {
|
|
|
commits map[string]bool
|
|
commits map[string]bool
|
|
|
repos []*regexp.Regexp
|
|
repos []*regexp.Regexp
|
|
|
}
|
|
}
|
|
|
- sshAuth *ssh.PublicKeys
|
|
|
|
|
|
|
+ FileRules []*Rule
|
|
|
|
|
+ sshAuth *ssh.PublicKeys
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// loadToml loads of the toml config containing regexes and whitelists.
|
|
// loadToml loads of the toml config containing regexes and whitelists.
|
|
@@ -109,10 +112,16 @@ func (config *Config) update(tomlConfig TomlConfig) error {
|
|
|
for _, rule := range tomlConfig.Rules {
|
|
for _, rule := range tomlConfig.Rules {
|
|
|
re := regexp.MustCompile(rule.Regex)
|
|
re := regexp.MustCompile(rule.Regex)
|
|
|
ranges, err := getEntropyRanges(rule.Entropies)
|
|
ranges, err := getEntropyRanges(rule.Entropies)
|
|
|
|
|
+ var fileTypes = []*regexp.Regexp{}
|
|
|
|
|
+ for _, regex := range rule.FileTypes {
|
|
|
|
|
+ fileTypes = append(fileTypes, regexp.MustCompile(regex))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
log.Errorf("could not create entropy range for %s, skipping rule", rule.Description)
|
|
log.Errorf("could not create entropy range for %s, skipping rule", rule.Description)
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
r := &Rule{
|
|
r := &Rule{
|
|
|
description: rule.Description,
|
|
description: rule.Description,
|
|
|
regex: re,
|
|
regex: re,
|
|
@@ -120,8 +129,14 @@ func (config *Config) update(tomlConfig TomlConfig) error {
|
|
|
tags: rule.Tags,
|
|
tags: rule.Tags,
|
|
|
entropies: ranges,
|
|
entropies: ranges,
|
|
|
entropyROI: rule.EntropyROI,
|
|
entropyROI: rule.EntropyROI,
|
|
|
|
|
+ fileTypes: fileTypes,
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if len(rule.Entropies) == 0 && rule.Regex == "" && len(fileTypes) != 0 {
|
|
|
|
|
+ config.FileRules = append(config.FileRules, r)
|
|
|
}
|
|
}
|
|
|
config.Rules = append(config.Rules, r)
|
|
config.Rules = append(config.Rules, r)
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// set whitelists
|
|
// set whitelists
|