mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-18 19:50:25 +08:00
CC防护增加“忽略常用文件”选项
This commit is contained in:
38
internal/utils/common_files.go
Normal file
38
internal/utils/common_files.go
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||||
|
|
||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/zero"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
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(),
|
||||||
|
".ttf": zero.New(),
|
||||||
|
".otf": zero.New(),
|
||||||
|
".fnt": zero.New(),
|
||||||
|
".svg": zero.New(),
|
||||||
|
".map": zero.New(),
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsCommonFileExtension 判断是否为常用文件扩展名
|
||||||
|
// 不区分大小写,且不限于是否加点符号(.)
|
||||||
|
func IsCommonFileExtension(ext string) bool {
|
||||||
|
if len(ext) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if ext[0] != '.' {
|
||||||
|
ext = "." + ext
|
||||||
|
}
|
||||||
|
_, ok := commonFileExtensionsMap[strings.ToLower(ext)]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
20
internal/utils/common_files_test.go
Normal file
20
internal/utils/common_files_test.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||||
|
|
||||||
|
package utils_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
||||||
|
"github.com/iwind/TeaGo/assert"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestIsCommonFileExtension(t *testing.T) {
|
||||||
|
var a = assert.NewAssertion(t)
|
||||||
|
|
||||||
|
a.IsTrue(utils.IsCommonFileExtension(".jpg"))
|
||||||
|
a.IsTrue(utils.IsCommonFileExtension("png"))
|
||||||
|
a.IsTrue(utils.IsCommonFileExtension("PNG"))
|
||||||
|
a.IsTrue(utils.IsCommonFileExtension(".PNG"))
|
||||||
|
a.IsTrue(utils.IsCommonFileExtension("Png"))
|
||||||
|
a.IsFalse(utils.IsCommonFileExtension("zip"))
|
||||||
|
}
|
||||||
@@ -4,32 +4,16 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/utils/counters"
|
"github.com/TeaOSLab/EdgeNode/internal/utils/counters"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
wafutils "github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"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"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
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(),
|
|
||||||
".ttf": zero.New(),
|
|
||||||
".otf": zero.New(),
|
|
||||||
".fnt": zero.New(),
|
|
||||||
".svg": zero.New(),
|
|
||||||
}
|
|
||||||
|
|
||||||
// CC2Checkpoint 新的CC
|
// CC2Checkpoint 新的CC
|
||||||
type CC2Checkpoint struct {
|
type CC2Checkpoint struct {
|
||||||
Checkpoint
|
Checkpoint
|
||||||
@@ -61,16 +45,12 @@ func (this *CC2Checkpoint) RequestValue(req requests.Request, param string, opti
|
|||||||
threshold = 1000
|
threshold = 1000
|
||||||
}**/
|
}**/
|
||||||
|
|
||||||
var ignoreCommonFiles = options.GetBool("ignoreCommonFiles")
|
if options.GetBool("ignoreCommonFiles") {
|
||||||
if ignoreCommonFiles {
|
|
||||||
var rawReq = req.WAFRaw()
|
var rawReq = req.WAFRaw()
|
||||||
if len(rawReq.Referer()) > 0 {
|
if len(rawReq.Referer()) > 0 {
|
||||||
var ext = filepath.Ext(rawReq.URL.Path)
|
var ext = filepath.Ext(rawReq.URL.Path)
|
||||||
if len(ext) > 0 {
|
if len(ext) > 0 && utils.IsCommonFileExtension(ext) {
|
||||||
_, ok := commonFileExtensionsMap[strings.ToLower(ext)]
|
return
|
||||||
if ok {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,6 +94,6 @@ func (this *CC2Checkpoint) ResponseValue(req requests.Request, resp *requests.Re
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CC2Checkpoint) CacheLife() utils.CacheLife {
|
func (this *CC2Checkpoint) CacheLife() wafutils.CacheLife {
|
||||||
return utils.CacheDisabled
|
return wafutils.CacheDisabled
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user