mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-12-24 14:06:35 +08:00
WAF检查项增加“所有报头名称”
This commit is contained in:
32
internal/waf/checkpoints/request_header_names.go
Normal file
32
internal/waf/checkpoints/request_header_names.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package checkpoints
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type RequestHeaderNamesCheckpoint struct {
|
||||
Checkpoint
|
||||
}
|
||||
|
||||
func (this *RequestHeaderNamesCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||
var headerNames = []string{}
|
||||
for k := range req.WAFRaw().Header {
|
||||
headerNames = append(headerNames, k)
|
||||
}
|
||||
value = strings.Join(headerNames, "\n")
|
||||
return
|
||||
}
|
||||
|
||||
func (this *RequestHeaderNamesCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||
if this.IsRequest() {
|
||||
return this.RequestValue(req, param, options, ruleId)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (this *RequestHeaderNamesCheckpoint) CacheLife() utils.CacheLife {
|
||||
return utils.CacheShortLife
|
||||
}
|
||||
23
internal/waf/checkpoints/request_header_names_test.go
Normal file
23
internal/waf/checkpoints/request_header_names_test.go
Normal file
@@ -0,0 +1,23 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package checkpoints_test
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeNode/internal/waf/checkpoints"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRequestHeaderNamesCheckpoint_RequestValue(t *testing.T) {
|
||||
var checkpoint = &checkpoints.RequestHeaderNamesCheckpoint{}
|
||||
rawReq, err := http.NewRequest(http.MethodGet, "https://example.com", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rawReq.Header.Set("Accept", "text/html")
|
||||
rawReq.Header.Set("User-Agent", "Chrome")
|
||||
rawReq.Header.Set("Accept-Encoding", "br, gzip")
|
||||
var req = requests.NewTestRequest(rawReq)
|
||||
t.Log(checkpoint.RequestValue(req, "", nil, 0))
|
||||
}
|
||||
@@ -226,6 +226,14 @@ var AllCheckpoints = []*CheckpointDefinition{
|
||||
Instance: new(RequestHeadersCheckpoint),
|
||||
Priority: 100,
|
||||
},
|
||||
{
|
||||
Name: "所有请求报头名称",
|
||||
Prefix: "headerNames",
|
||||
Description: "使用换行符(\\n)隔开的报头名称字符串,每行一个名称",
|
||||
HasParams: false,
|
||||
Instance: new(RequestHeaderNamesCheckpoint),
|
||||
Priority: 100,
|
||||
},
|
||||
{
|
||||
Name: "单个Header值",
|
||||
Prefix: "header",
|
||||
|
||||
Reference in New Issue
Block a user