add body_type in custom rule
This commit is contained in:
parent
2e0b9683f3
commit
84ffde1844
|
@ -43,6 +43,13 @@ var matchMap map[string]string = map[string]string{
|
||||||
"le": "@le",
|
"le": "@le",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var bodyTypeMatch map[string]string = map[string]string{
|
||||||
|
"json": "JSON",
|
||||||
|
"xml": "XML",
|
||||||
|
"multipart": "MULTIPART",
|
||||||
|
"urlencoded": "URLENCODED",
|
||||||
|
}
|
||||||
|
|
||||||
func (m *ModsecurityRule) Build(rule *CustomRule, waapRuleName string) (string, []uint32, error) {
|
func (m *ModsecurityRule) Build(rule *CustomRule, waapRuleName string) (string, []uint32, error) {
|
||||||
|
|
||||||
rules, err := m.buildRules(rule, waapRuleName, false, 0)
|
rules, err := m.buildRules(rule, waapRuleName, false, 0)
|
||||||
|
@ -146,6 +153,14 @@ func (m *ModsecurityRule) buildRules(rule *CustomRule, waapRuleName string, and
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if rule.BodyType != "" {
|
||||||
|
if mappedBodyType, ok := bodyTypeMatch[rule.BodyType]; ok {
|
||||||
|
r.WriteString(fmt.Sprintf(",ctl:requestBodyProcessor=%s", mappedBodyType))
|
||||||
|
} else {
|
||||||
|
return nil, fmt.Errorf("unknown body type '%s'", rule.BodyType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if and {
|
if and {
|
||||||
r.WriteString(",chain")
|
r.WriteString(",chain")
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ type CustomRule struct {
|
||||||
Transform []string `yaml:"transform"` //t:lowercase, t:uppercase, etc
|
Transform []string `yaml:"transform"` //t:lowercase, t:uppercase, etc
|
||||||
And []CustomRule `yaml:"and,omitempty"`
|
And []CustomRule `yaml:"and,omitempty"`
|
||||||
Or []CustomRule `yaml:"or,omitempty"`
|
Or []CustomRule `yaml:"or,omitempty"`
|
||||||
|
BodyType string `yaml:"body_type,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *CustomRule) Convert(ruleType string, waapRuleName string) (string, []uint32, error) {
|
func (v *CustomRule) Convert(ruleType string, waapRuleName string) (string, []uint32, error) {
|
||||||
|
|
Loading…
Reference in a new issue