WAF中添加正则相关规则时校验正则表达式

This commit is contained in:
刘祥超
2021-09-10 10:31:56 +08:00
parent 6284db1bc8
commit 699ed00e40

View File

@@ -1,6 +1,7 @@
package firewallconfigs
import (
"errors"
"regexp"
"strings"
)
@@ -21,6 +22,20 @@ type HTTPFirewallRule struct {
func (this *HTTPFirewallRule) Init() error {
// TODO 执行更严谨的校验
switch this.Operator {
case HTTPFirewallRuleOperatorMatch:
_, err := regexp.Compile(this.Value)
if err != nil {
return errors.New("regexp validate failed: " + err.Error())
}
case HTTPFirewallRuleOperatorNotMatch:
_, err := regexp.Compile(this.Value)
if err != nil {
return errors.New("regexp validate failed: " + err.Error())
}
}
return nil
}