mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-11-27 23:20:26 +08:00
[WAF]规则中增加请求Header长度限制和响应Header长度限制
This commit is contained in:
@@ -14,10 +14,11 @@ func NewKeyValue(name string, value string) *KeyValue {
|
|||||||
|
|
||||||
// check point definition
|
// check point definition
|
||||||
type HTTPFirewallCheckpointDefinition struct {
|
type HTTPFirewallCheckpointDefinition struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"` // 名称
|
||||||
Description string `json:"description"`
|
Description string `json:"description"` // 描述
|
||||||
Prefix string `json:"prefix"`
|
Prefix string `json:"prefix"` // 前缀
|
||||||
IsRequest bool `json:"isRequest"`
|
IsRequest bool `json:"isRequest"` // 是否为请求
|
||||||
Params []*KeyValue `json:"params"`
|
Params []*KeyValue `json:"params"` // 参数
|
||||||
Options []OptionInterface `json:"options"`
|
Options []OptionInterface `json:"options"` // 选项
|
||||||
|
IsComposed bool `json:"isComposed"` // 是否为组合的checkpoint
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,20 @@ import (
|
|||||||
|
|
||||||
// all check points list
|
// all check points list
|
||||||
var AllCheckpoints = []*HTTPFirewallCheckpointDefinition{
|
var AllCheckpoints = []*HTTPFirewallCheckpointDefinition{
|
||||||
|
{
|
||||||
|
Name: "通用请求Header长度限制",
|
||||||
|
Prefix: "requestGeneralHeaderLength",
|
||||||
|
Description: "通用Header比如Cache-Control、Accept之类的长度限制,防止缓冲区溢出攻击",
|
||||||
|
IsRequest: true,
|
||||||
|
IsComposed: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "通用响应Header长度限制",
|
||||||
|
Prefix: "responseGeneralHeaderLength",
|
||||||
|
Description: "通用Header比如Cache-Control、Date之类的长度限制,防止缓冲区溢出攻击",
|
||||||
|
IsRequest: false,
|
||||||
|
IsComposed: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "客户端地址(IP)",
|
Name: "客户端地址(IP)",
|
||||||
Prefix: "remoteAddr",
|
Prefix: "remoteAddr",
|
||||||
@@ -268,12 +282,22 @@ var AllCheckpoints = []*HTTPFirewallCheckpointDefinition{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// find a check point definition
|
// 查找Checkpoint定义
|
||||||
func FindCheckpointDefinition(prefix string) *HTTPFirewallCheckpointDefinition {
|
func FindCheckpointDefinition(prefix string) *HTTPFirewallCheckpointDefinition {
|
||||||
for _, def := range AllCheckpoints {
|
for _, checkpoint := range AllCheckpoints {
|
||||||
if def.Prefix == prefix {
|
if checkpoint.Prefix == prefix {
|
||||||
return def
|
return checkpoint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 判断Checkpoint是否为组合的
|
||||||
|
func CheckCheckpointIsComposed(prefix string) bool {
|
||||||
|
for _, checkpoint := range AllCheckpoints {
|
||||||
|
if checkpoint.Prefix == prefix {
|
||||||
|
return checkpoint.IsComposed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
package firewallconfigs
|
package firewallconfigs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var namedParamReg = regexp.MustCompile(`^\${\s*(.+)\s*}$`)
|
||||||
|
|
||||||
type HTTPFirewallRule struct {
|
type HTTPFirewallRule struct {
|
||||||
Id int64 `yaml:"id" json:"id"`
|
Id int64 `yaml:"id" json:"id"`
|
||||||
IsOn bool `yaml:"isOn" json:"isOn"`
|
IsOn bool `yaml:"isOn" json:"isOn"`
|
||||||
@@ -15,3 +22,13 @@ func (this *HTTPFirewallRule) Init() error {
|
|||||||
// TODO 执行更严谨的校验
|
// TODO 执行更严谨的校验
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *HTTPFirewallRule) Prefix() string {
|
||||||
|
result := namedParamReg.FindStringSubmatch(this.Param)
|
||||||
|
if len(result) > 0 {
|
||||||
|
param := result[1]
|
||||||
|
pieces := strings.Split(param, ".")
|
||||||
|
return pieces[0]
|
||||||
|
}
|
||||||
|
return this.Param
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user