From e44f9cc2fb25eba991c31f32e6f3b891bddd00c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Fri, 15 Jul 2022 12:02:19 +0800 Subject: [PATCH] =?UTF-8?q?cc2=E5=A2=9E=E5=8A=A0=E5=BF=BD=E7=95=A5?= =?UTF-8?q?=E5=B8=B8=E8=A7=81=E6=96=87=E4=BB=B6=E6=89=A9=E5=B1=95=E5=90=8D?= =?UTF-8?q?=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/waf/checkpoints/cc2.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/internal/waf/checkpoints/cc2.go b/internal/waf/checkpoints/cc2.go index 35d1011..ead9c64 100644 --- a/internal/waf/checkpoints/cc2.go +++ b/internal/waf/checkpoints/cc2.go @@ -5,14 +5,28 @@ package checkpoints import ( "github.com/TeaOSLab/EdgeNode/internal/ttlcache" "github.com/TeaOSLab/EdgeNode/internal/waf/requests" + "github.com/TeaOSLab/EdgeNode/internal/zero" "github.com/iwind/TeaGo/maps" "github.com/iwind/TeaGo/types" + "path/filepath" "strings" "time" ) 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 type CC2Checkpoint struct { Checkpoint @@ -38,6 +52,20 @@ func (this *CC2Checkpoint) RequestValue(req requests.Request, param string, opti 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) return