mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-12-25 03:26:36 +08:00
WAF中添加正则相关规则时校验正则表达式
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user