|
@@ -59,7 +59,7 @@ type Config struct {
|
|
|
Description string
|
|
Description string
|
|
|
Rules map[string]Rule
|
|
Rules map[string]Rule
|
|
|
Allowlist Allowlist
|
|
Allowlist Allowlist
|
|
|
- Keywords []string
|
|
|
|
|
|
|
+ Keywords map[string]struct{}
|
|
|
|
|
|
|
|
// used to keep sarif results consistent
|
|
// used to keep sarif results consistent
|
|
|
OrderedRules []string
|
|
OrderedRules []string
|
|
@@ -75,10 +75,10 @@ type Extend struct {
|
|
|
|
|
|
|
|
func (vc *ViperConfig) Translate() (Config, error) {
|
|
func (vc *ViperConfig) Translate() (Config, error) {
|
|
|
var (
|
|
var (
|
|
|
- keywords []string
|
|
|
|
|
|
|
+ keywords = make(map[string]struct{})
|
|
|
orderedRules []string
|
|
orderedRules []string
|
|
|
|
|
+ rulesMap = make(map[string]Rule)
|
|
|
)
|
|
)
|
|
|
- rulesMap := make(map[string]Rule)
|
|
|
|
|
|
|
|
|
|
for _, r := range vc.Rules {
|
|
for _, r := range vc.Rules {
|
|
|
var allowlistRegexes []*regexp.Regexp
|
|
var allowlistRegexes []*regexp.Regexp
|
|
@@ -94,7 +94,7 @@ func (vc *ViperConfig) Translate() (Config, error) {
|
|
|
r.Keywords = []string{}
|
|
r.Keywords = []string{}
|
|
|
} else {
|
|
} else {
|
|
|
for _, k := range r.Keywords {
|
|
for _, k := range r.Keywords {
|
|
|
- keywords = append(keywords, strings.ToLower(k))
|
|
|
|
|
|
|
+ keywords[strings.ToLower(k)] = struct{}{}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -245,7 +245,9 @@ func (c *Config) extend(extensionConfig Config) {
|
|
|
if !ok {
|
|
if !ok {
|
|
|
// Rule doesn't exist, add it to the config.
|
|
// Rule doesn't exist, add it to the config.
|
|
|
c.Rules[ruleID] = baseRule
|
|
c.Rules[ruleID] = baseRule
|
|
|
- c.Keywords = append(c.Keywords, baseRule.Keywords...)
|
|
|
|
|
|
|
+ for _, k := range baseRule.Keywords {
|
|
|
|
|
+ c.Keywords[k] = struct{}{}
|
|
|
|
|
+ }
|
|
|
c.OrderedRules = append(c.OrderedRules, ruleID)
|
|
c.OrderedRules = append(c.OrderedRules, ruleID)
|
|
|
} else {
|
|
} else {
|
|
|
// Rule exists, merge our changes into the base.
|
|
// Rule exists, merge our changes into the base.
|
|
@@ -255,10 +257,12 @@ func (c *Config) extend(extensionConfig Config) {
|
|
|
baseRule.Allowlist.RegexTarget = currentRule.Allowlist.RegexTarget
|
|
baseRule.Allowlist.RegexTarget = currentRule.Allowlist.RegexTarget
|
|
|
baseRule.Allowlist.StopWords = append(baseRule.Allowlist.StopWords, currentRule.Allowlist.StopWords...)
|
|
baseRule.Allowlist.StopWords = append(baseRule.Allowlist.StopWords, currentRule.Allowlist.StopWords...)
|
|
|
// The keywords from the base rule and the extended rule must be merged into the global keywords list
|
|
// The keywords from the base rule and the extended rule must be merged into the global keywords list
|
|
|
- c.Keywords = append(c.Keywords, baseRule.Keywords...)
|
|
|
|
|
- c.Keywords = append(c.Keywords, currentRule.Keywords...)
|
|
|
|
|
-
|
|
|
|
|
- delete(c.Rules, ruleID)
|
|
|
|
|
|
|
+ for _, k := range baseRule.Keywords {
|
|
|
|
|
+ c.Keywords[k] = struct{}{}
|
|
|
|
|
+ }
|
|
|
|
|
+ for _, k := range currentRule.Keywords {
|
|
|
|
|
+ c.Keywords[k] = struct{}{}
|
|
|
|
|
+ }
|
|
|
c.Rules[ruleID] = baseRule
|
|
c.Rules[ruleID] = baseRule
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|