mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-03 23:20:25 +08:00
请求变量增加${cname},WAF checkpoint增加cname和isCNAME
This commit is contained in:
@@ -758,6 +758,8 @@ func (this *HTTPRequest) Format(source string) string {
|
||||
return strconv.FormatInt(this.requestFromTime.Unix(), 10)
|
||||
case "host":
|
||||
return this.ReqHost
|
||||
case "cname":
|
||||
return this.ReqServer.CNameDomain
|
||||
case "referer":
|
||||
return this.RawReq.Referer()
|
||||
case "referer.host":
|
||||
|
||||
22
internal/waf/checkpoints/request_cname.go
Normal file
22
internal/waf/checkpoints/request_cname.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package checkpoints
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type RequestCNAMECheckpoint struct {
|
||||
Checkpoint
|
||||
}
|
||||
|
||||
func (this *RequestCNAMECheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
||||
value = req.Format("${cname}")
|
||||
return
|
||||
}
|
||||
|
||||
func (this *RequestCNAMECheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
||||
if this.IsRequest() {
|
||||
return this.RequestValue(req, param, options, ruleId)
|
||||
}
|
||||
return
|
||||
}
|
||||
26
internal/waf/checkpoints/request_is_cname.go
Normal file
26
internal/waf/checkpoints/request_is_cname.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package checkpoints
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type RequestIsCNAMECheckpoint struct {
|
||||
Checkpoint
|
||||
}
|
||||
|
||||
func (this *RequestIsCNAMECheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
||||
if req.Format("${cname}") == req.Format("${host}") {
|
||||
value = 1
|
||||
} else {
|
||||
value = 0
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (this *RequestIsCNAMECheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
||||
if this.IsRequest() {
|
||||
return this.RequestValue(req, param, options, ruleId)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -146,6 +146,22 @@ var AllCheckpoints = []*CheckpointDefinition{
|
||||
Instance: new(RequestHostCheckpoint),
|
||||
Priority: 100,
|
||||
},
|
||||
{
|
||||
Name: "CNAME",
|
||||
Prefix: "cname",
|
||||
Description: "当前网站服务CNAME,比如38b48e4f.goedge.cn",
|
||||
HasParams: false,
|
||||
Instance: new(RequestCNAMECheckpoint),
|
||||
Priority: 100,
|
||||
},
|
||||
{
|
||||
Name: "是否为CNAME",
|
||||
Prefix: "isCNAME",
|
||||
Description: "是否为CNAME,值为1(是)或0(否)",
|
||||
HasParams: false,
|
||||
Instance: new(RequestIsCNAMECheckpoint),
|
||||
Priority: 100,
|
||||
},
|
||||
{
|
||||
Name: "请求来源URL",
|
||||
Prefix: "referer",
|
||||
|
||||
Reference in New Issue
Block a user