cc2增加忽略常见文件扩展名选项

This commit is contained in:
刘祥超
2022-07-15 12:02:19 +08:00
parent c6823ae3a8
commit e44f9cc2fb

View File

@@ -5,14 +5,28 @@ package checkpoints
import ( import (
"github.com/TeaOSLab/EdgeNode/internal/ttlcache" "github.com/TeaOSLab/EdgeNode/internal/ttlcache"
"github.com/TeaOSLab/EdgeNode/internal/waf/requests" "github.com/TeaOSLab/EdgeNode/internal/waf/requests"
"github.com/TeaOSLab/EdgeNode/internal/zero"
"github.com/iwind/TeaGo/maps" "github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/types" "github.com/iwind/TeaGo/types"
"path/filepath"
"strings" "strings"
"time" "time"
) )
var ccCache = ttlcache.NewCache() var ccCache = ttlcache.NewCache()
var commonFileExtensionsMap = map[string]zero.Zero{
".ico": zero.New(),
".jpg": zero.New(),
".jpeg": zero.New(),
".gif": zero.New(),
".png": zero.New(),
".webp": zero.New(),
".woff2": zero.New(),
".js": zero.New(),
".css": zero.New(),
}
// CC2Checkpoint 新的CC // CC2Checkpoint 新的CC
type CC2Checkpoint struct { type CC2Checkpoint struct {
Checkpoint Checkpoint
@@ -38,6 +52,20 @@ func (this *CC2Checkpoint) RequestValue(req requests.Request, param string, opti
threshold = 1000 threshold = 1000
} }
var ignoreCommonFiles = options.GetBool("ignoreCommonFiles")
if ignoreCommonFiles {
var rawReq = req.WAFRaw()
if len(rawReq.Referer()) > 0 {
var ext = filepath.Ext(rawReq.URL.Path)
if len(ext) > 0 {
_, ok := commonFileExtensionsMap[strings.ToLower(ext)]
if ok {
return
}
}
}
}
value = ccCache.IncreaseInt64("WAF-CC-"+strings.Join(keyValues, "@"), 1, time.Now().Unix()+period, false) value = ccCache.IncreaseInt64("WAF-CC-"+strings.Join(keyValues, "@"), 1, time.Now().Unix()+period, false)
return return