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

This commit is contained in:
GoEdgeLab
2021-09-10 10:31:56 +08:00
parent b64e22466d
commit f4fdbdc4d7

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
}