mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-19 20:40:26 +08:00
优化WAF正则表达式缓存时间
This commit is contained in:
@@ -3,12 +3,12 @@ package checkpoints
|
|||||||
import (
|
import (
|
||||||
"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"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
"regexp"
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
// CCCheckpoint ${cc.arg}
|
// CCCheckpoint ${cc.arg}
|
||||||
// TODO implement more traffic rules
|
// TODO implement more traffic rules
|
||||||
type CCCheckpoint struct {
|
type CCCheckpoint struct {
|
||||||
@@ -23,7 +23,7 @@ func (this *CCCheckpoint) Start() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CCCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *CCCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
value = 0
|
value = 0
|
||||||
|
|
||||||
periodString, ok := options["period"]
|
periodString, ok := options["period"]
|
||||||
@@ -103,7 +103,7 @@ func (this *CCCheckpoint) RequestValue(req requests.Request, param string, optio
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CCCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *CCCheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
@@ -188,3 +188,7 @@ func (this *CCCheckpoint) Options() []OptionInterface {
|
|||||||
func (this *CCCheckpoint) Stop() {
|
func (this *CCCheckpoint) Stop() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *CCCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheDisabled
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"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"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/zero"
|
"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"
|
||||||
@@ -34,7 +35,7 @@ type CC2Checkpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CC2Checkpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *CC2Checkpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
var keys = options.GetSlice("keys")
|
var keys = options.GetSlice("keys")
|
||||||
var keyValues = []string{}
|
var keyValues = []string{}
|
||||||
var hasRemoteAddr = false
|
var hasRemoteAddr = false
|
||||||
@@ -104,10 +105,14 @@ func (this *CC2Checkpoint) RequestValue(req requests.Request, param string, opti
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CC2Checkpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *CC2Checkpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *CC2Checkpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheDisabled
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -17,10 +18,10 @@ type CheckpointInterface interface {
|
|||||||
IsComposed() bool
|
IsComposed() bool
|
||||||
|
|
||||||
// RequestValue get request value
|
// RequestValue get request value
|
||||||
RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error)
|
RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error)
|
||||||
|
|
||||||
// ResponseValue get response value
|
// ResponseValue get response value
|
||||||
ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error)
|
ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error)
|
||||||
|
|
||||||
// ParamOptions param option list
|
// ParamOptions param option list
|
||||||
ParamOptions() *ParamOptions
|
ParamOptions() *ParamOptions
|
||||||
@@ -37,6 +38,9 @@ type CheckpointInterface interface {
|
|||||||
// SetPriority set priority
|
// SetPriority set priority
|
||||||
SetPriority(priority int)
|
SetPriority(priority int)
|
||||||
|
|
||||||
// get priority
|
// Priority get priority
|
||||||
Priority() int
|
Priority() int
|
||||||
|
|
||||||
|
// CacheLife regexp cache life
|
||||||
|
CacheLife() utils.CacheLife
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -10,7 +11,7 @@ type RequestAllCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestAllCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestAllCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
var valueBytes = []byte{}
|
var valueBytes = []byte{}
|
||||||
if len(req.WAFRaw().RequestURI) > 0 {
|
if len(req.WAFRaw().RequestURI) > 0 {
|
||||||
valueBytes = append(valueBytes, req.WAFRaw().RequestURI...)
|
valueBytes = append(valueBytes, req.WAFRaw().RequestURI...)
|
||||||
@@ -46,10 +47,14 @@ func (this *RequestAllCheckpoint) RequestValue(req requests.Request, param strin
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestAllCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestAllCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
value = ""
|
value = ""
|
||||||
if this.IsRequest() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestAllCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheShortLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,13 +10,17 @@ type RequestArgCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestArgCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestArgCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
return req.WAFRaw().URL.Query().Get(param), hasRequestBody, nil, nil
|
return req.WAFRaw().URL.Query().Get(param), hasRequestBody, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestArgCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestArgCheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestArgCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheMiddleLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,14 +10,18 @@ type RequestArgsCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestArgsCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestArgsCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
value = req.WAFRaw().URL.RawQuery
|
value = req.WAFRaw().URL.RawQuery
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestArgsCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestArgsCheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestArgsCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheMiddleLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -10,7 +11,7 @@ type RequestBodyCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestBodyCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestBodyCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
if this.RequestBodyIsEmpty(req) {
|
if this.RequestBodyIsEmpty(req) {
|
||||||
value = ""
|
value = ""
|
||||||
return
|
return
|
||||||
@@ -37,9 +38,13 @@ func (this *RequestBodyCheckpoint) RequestValue(req requests.Request, param stri
|
|||||||
return bodyData, hasRequestBody, nil, nil
|
return bodyData, hasRequestBody, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestBodyCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestBodyCheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestBodyCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheDisabled
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,14 +10,18 @@ type RequestCNAMECheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestCNAMECheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestCNAMECheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
value = req.Format("${cname}")
|
value = req.Format("${cname}")
|
||||||
return
|
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) {
|
func (this *RequestCNAMECheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestCNAMECheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheLongLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,14 +10,18 @@ type RequestContentTypeCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestContentTypeCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestContentTypeCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
value = req.WAFRaw().Header.Get("Content-Type")
|
value = req.WAFRaw().Header.Get("Content-Type")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestContentTypeCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestContentTypeCheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestContentTypeCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheLongLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,7 +10,7 @@ type RequestCookieCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestCookieCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestCookieCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
cookie, err := req.WAFRaw().Cookie(param)
|
cookie, err := req.WAFRaw().Cookie(param)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
value = ""
|
value = ""
|
||||||
@@ -20,9 +21,13 @@ func (this *RequestCookieCheckpoint) RequestValue(req requests.Request, param st
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestCookieCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestCookieCheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestCookieCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheMiddleLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -11,7 +12,7 @@ type RequestCookiesCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestCookiesCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestCookiesCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
var cookies = []string{}
|
var cookies = []string{}
|
||||||
for _, cookie := range req.WAFRaw().Cookies() {
|
for _, cookie := range req.WAFRaw().Cookies() {
|
||||||
cookies = append(cookies, url.QueryEscape(cookie.Name)+"="+url.QueryEscape(cookie.Value))
|
cookies = append(cookies, url.QueryEscape(cookie.Name)+"="+url.QueryEscape(cookie.Value))
|
||||||
@@ -20,9 +21,13 @@ func (this *RequestCookiesCheckpoint) RequestValue(req requests.Request, param s
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestCookiesCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestCookiesCheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestCookiesCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheShortLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"net/url"
|
"net/url"
|
||||||
)
|
)
|
||||||
@@ -11,7 +12,7 @@ type RequestFormArgCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestFormArgCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestFormArgCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
hasRequestBody = true
|
hasRequestBody = true
|
||||||
|
|
||||||
if this.RequestBodyIsEmpty(req) {
|
if this.RequestBodyIsEmpty(req) {
|
||||||
@@ -41,9 +42,13 @@ func (this *RequestFormArgCheckpoint) RequestValue(req requests.Request, param s
|
|||||||
return values.Get(param), hasRequestBody, nil, nil
|
return values.Get(param), hasRequestBody, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestFormArgCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestFormArgCheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestFormArgCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheMiddleLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
)
|
)
|
||||||
@@ -14,7 +15,7 @@ func (this *RequestGeneralHeaderLengthCheckpoint) IsComposed() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestGeneralHeaderLengthCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestGeneralHeaderLengthCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
value = false
|
value = false
|
||||||
|
|
||||||
var headers = options.GetSlice("headers")
|
var headers = options.GetSlice("headers")
|
||||||
@@ -35,6 +36,10 @@ func (this *RequestGeneralHeaderLengthCheckpoint) RequestValue(req requests.Requ
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestGeneralHeaderLengthCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestGeneralHeaderLengthCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestGeneralHeaderLengthCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheDisabled
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,11 +16,15 @@ func (this *RequestGeoCityNameCheckpoint) IsComposed() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestGeoCityNameCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestGeoCityNameCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
value = req.Format("${geo.city.name}")
|
value = req.Format("${geo.city.name}")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestGeoCityNameCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestGeoCityNameCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestGeoCityNameCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheLongLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,11 +16,15 @@ func (this *RequestGeoCountryNameCheckpoint) IsComposed() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestGeoCountryNameCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestGeoCountryNameCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
value = req.Format("${geo.country.name}")
|
value = req.Format("${geo.country.name}")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestGeoCountryNameCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestGeoCountryNameCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestGeoCountryNameCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheLongLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,11 +16,15 @@ func (this *RequestGeoProvinceNameCheckpoint) IsComposed() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestGeoProvinceNameCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestGeoProvinceNameCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
value = req.Format("${geo.province.name}")
|
value = req.Format("${geo.province.name}")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestGeoProvinceNameCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestGeoProvinceNameCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestGeoProvinceNameCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheLongLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -10,7 +11,7 @@ type RequestHeaderCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestHeaderCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestHeaderCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
v, found := req.WAFRaw().Header[param]
|
v, found := req.WAFRaw().Header[param]
|
||||||
if !found {
|
if !found {
|
||||||
value = ""
|
value = ""
|
||||||
@@ -20,9 +21,13 @@ func (this *RequestHeaderCheckpoint) RequestValue(req requests.Request, param st
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestHeaderCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestHeaderCheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestHeaderCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheMiddleLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -11,7 +12,7 @@ type RequestHeadersCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestHeadersCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestHeadersCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
var headers = []string{}
|
var headers = []string{}
|
||||||
for k, v := range req.WAFRaw().Header {
|
for k, v := range req.WAFRaw().Header {
|
||||||
for _, subV := range v {
|
for _, subV := range v {
|
||||||
@@ -23,9 +24,13 @@ func (this *RequestHeadersCheckpoint) RequestValue(req requests.Request, param s
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestHeadersCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestHeadersCheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestHeadersCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheShortLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,14 +10,18 @@ type RequestHostCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestHostCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestHostCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
value = req.WAFRaw().Host
|
value = req.WAFRaw().Host
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestHostCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestHostCheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestHostCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheLongLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,7 +10,7 @@ type RequestIsCNAMECheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestIsCNAMECheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestIsCNAMECheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
if req.Format("${cname}") == req.Format("${host}") {
|
if req.Format("${cname}") == req.Format("${host}") {
|
||||||
value = 1
|
value = 1
|
||||||
} else {
|
} else {
|
||||||
@@ -18,9 +19,13 @@ func (this *RequestIsCNAMECheckpoint) RequestValue(req requests.Request, param s
|
|||||||
return
|
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) {
|
func (this *RequestIsCNAMECheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestIsCNAMECheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheLongLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,11 +16,15 @@ func (this *RequestISPNameCheckpoint) IsComposed() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestISPNameCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestISPNameCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
value = req.Format("${isp.name}")
|
value = req.Format("${isp.name}")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestISPNameCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestISPNameCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestISPNameCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheLongLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
wafutils "github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -13,7 +14,7 @@ type RequestJSONArgCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestJSONArgCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestJSONArgCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
var bodyData = req.WAFGetCacheBody()
|
var bodyData = req.WAFGetCacheBody()
|
||||||
hasRequestBody = true
|
hasRequestBody = true
|
||||||
if len(bodyData) == 0 {
|
if len(bodyData) == 0 {
|
||||||
@@ -28,7 +29,7 @@ func (this *RequestJSONArgCheckpoint) RequestValue(req requests.Request, param s
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO improve performance
|
// TODO improve performance
|
||||||
var m interface{} = nil
|
var m any = nil
|
||||||
err := json.Unmarshal(bodyData, &m)
|
err := json.Unmarshal(bodyData, &m)
|
||||||
if err != nil || m == nil {
|
if err != nil || m == nil {
|
||||||
return "", hasRequestBody, nil, err
|
return "", hasRequestBody, nil, err
|
||||||
@@ -41,9 +42,13 @@ func (this *RequestJSONArgCheckpoint) RequestValue(req requests.Request, param s
|
|||||||
return "", hasRequestBody, nil, nil
|
return "", hasRequestBody, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestJSONArgCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestJSONArgCheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestJSONArgCheckpoint) CacheLife() wafutils.CacheLife {
|
||||||
|
return wafutils.CacheMiddleLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,14 +10,18 @@ type RequestLengthCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestLengthCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestLengthCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
value = req.WAFRaw().ContentLength
|
value = req.WAFRaw().ContentLength
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestLengthCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestLengthCheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestLengthCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheShortLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,14 +10,18 @@ type RequestMethodCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestMethodCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestMethodCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
value = req.WAFRaw().Method
|
value = req.WAFRaw().Method
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestMethodCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestMethodCheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestMethodCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheLongLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,13 +10,17 @@ type RequestPathCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestPathCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestPathCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
return req.WAFRaw().URL.Path, false, nil, nil
|
return req.WAFRaw().URL.Path, false, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestPathCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestPathCheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestPathCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheMiddleLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,14 +10,18 @@ type RequestProtoCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestProtoCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestProtoCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
value = req.WAFRaw().Proto
|
value = req.WAFRaw().Proto
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestProtoCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestProtoCheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestProtoCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheLongLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"net"
|
"net"
|
||||||
)
|
)
|
||||||
@@ -10,7 +11,7 @@ type RequestRawRemoteAddrCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestRawRemoteAddrCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestRawRemoteAddrCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
host, _, err := net.SplitHostPort(req.WAFRaw().RemoteAddr)
|
host, _, err := net.SplitHostPort(req.WAFRaw().RemoteAddr)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
value = host
|
value = host
|
||||||
@@ -20,9 +21,13 @@ func (this *RequestRawRemoteAddrCheckpoint) RequestValue(req requests.Request, p
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestRawRemoteAddrCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestRawRemoteAddrCheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestRawRemoteAddrCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheShortLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,14 +10,18 @@ type RequestRefererCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestRefererCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestRefererCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
value = req.WAFRaw().Referer()
|
value = req.WAFRaw().Referer()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestRefererCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestRefererCheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestRefererCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheShortLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package checkpoints
|
|||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -17,7 +18,7 @@ type RequestRefererBlockCheckpoint struct {
|
|||||||
|
|
||||||
// RequestValue 计算checkpoint值
|
// RequestValue 计算checkpoint值
|
||||||
// 选项:allowEmpty, allowSameDomain, allowDomains
|
// 选项:allowEmpty, allowSameDomain, allowDomains
|
||||||
func (this *RequestRefererBlockCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestRefererBlockCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
var checkOrigin = options.GetBool("checkOrigin")
|
var checkOrigin = options.GetBool("checkOrigin")
|
||||||
var referer = req.WAFRaw().Referer()
|
var referer = req.WAFRaw().Referer()
|
||||||
if len(referer) == 0 && checkOrigin {
|
if len(referer) == 0 && checkOrigin {
|
||||||
@@ -94,6 +95,10 @@ func (this *RequestRefererBlockCheckpoint) RequestValue(req requests.Request, pa
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestRefererBlockCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestRefererBlockCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestRefererBlockCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheLongLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,14 +10,18 @@ type RequestRemoteAddrCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestRemoteAddrCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestRemoteAddrCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
value = req.WAFRemoteIP()
|
value = req.WAFRemoteIP()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestRemoteAddrCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestRemoteAddrCheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestRemoteAddrCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheShortLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
"net"
|
"net"
|
||||||
@@ -11,7 +12,7 @@ type RequestRemotePortCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestRemotePortCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestRemotePortCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
_, port, err := net.SplitHostPort(req.WAFRaw().RemoteAddr)
|
_, port, err := net.SplitHostPort(req.WAFRaw().RemoteAddr)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
value = types.Int(port)
|
value = types.Int(port)
|
||||||
@@ -21,9 +22,13 @@ func (this *RequestRemotePortCheckpoint) RequestValue(req requests.Request, para
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestRemotePortCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestRemotePortCheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestRemotePortCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheMiddleLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,7 +10,7 @@ type RequestRemoteUserCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestRemoteUserCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestRemoteUserCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
username, _, ok := req.WAFRaw().BasicAuth()
|
username, _, ok := req.WAFRaw().BasicAuth()
|
||||||
if !ok {
|
if !ok {
|
||||||
value = ""
|
value = ""
|
||||||
@@ -19,9 +20,13 @@ func (this *RequestRemoteUserCheckpoint) RequestValue(req requests.Request, para
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestRemoteUserCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestRemoteUserCheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestRemoteUserCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheMiddleLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,14 +10,18 @@ type RequestSchemeCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestSchemeCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestSchemeCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
value = req.Format("${scheme}")
|
value = req.Format("${scheme}")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestSchemeCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestSchemeCheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestSchemeCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheLongLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package checkpoints
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/lists"
|
"github.com/iwind/TeaGo/lists"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
@@ -22,7 +23,7 @@ type RequestUploadCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestUploadCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestUploadCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
if this.RequestBodyIsEmpty(req) {
|
if this.RequestBodyIsEmpty(req) {
|
||||||
value = ""
|
value = ""
|
||||||
return
|
return
|
||||||
@@ -213,7 +214,7 @@ func (this *RequestUploadCheckpoint) RequestValue(req requests.Request, param st
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestUploadCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestUploadCheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
@@ -229,3 +230,7 @@ func (this *RequestUploadCheckpoint) ParamOptions() *ParamOptions {
|
|||||||
option.AddParam("表单字段名", "field")
|
option.AddParam("表单字段名", "field")
|
||||||
return option
|
return option
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestUploadCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheMiddleLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,7 +10,7 @@ type RequestURICheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestURICheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestURICheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
if len(req.WAFRaw().RequestURI) > 0 {
|
if len(req.WAFRaw().RequestURI) > 0 {
|
||||||
value = req.WAFRaw().RequestURI
|
value = req.WAFRaw().RequestURI
|
||||||
} else if req.WAFRaw().URL != nil {
|
} else if req.WAFRaw().URL != nil {
|
||||||
@@ -18,9 +19,13 @@ func (this *RequestURICheckpoint) RequestValue(req requests.Request, param strin
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestURICheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestURICheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestURICheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheShortLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,13 +10,17 @@ type RequestURLCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestURLCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestURLCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
return req.Format("${requestURL}"), hasRequestBody, nil, nil
|
return req.Format("${requestURL}"), hasRequestBody, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestURLCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestURLCheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestURLCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheShortLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,14 +10,18 @@ type RequestUserAgentCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestUserAgentCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestUserAgentCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
value = req.WAFRaw().UserAgent()
|
value = req.WAFRaw().UserAgent()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestUserAgentCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *RequestUserAgentCheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RequestUserAgentCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheShortLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package checkpoints
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
@@ -16,12 +17,12 @@ func (this *ResponseBodyCheckpoint) IsRequest() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ResponseBodyCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *ResponseBodyCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
value = ""
|
value = ""
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ResponseBodyCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *ResponseBodyCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
if resp.ContentLength == 0 {
|
if resp.ContentLength == 0 {
|
||||||
value = ""
|
value = ""
|
||||||
return
|
return
|
||||||
@@ -45,3 +46,7 @@ func (this *ResponseBodyCheckpoint) ResponseValue(req requests.Request, resp *re
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *ResponseBodyCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheMiddleLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -14,15 +15,19 @@ func (this *ResponseBytesSentCheckpoint) IsRequest() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ResponseBytesSentCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *ResponseBytesSentCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
value = 0
|
value = 0
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ResponseBytesSentCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *ResponseBytesSentCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
value = 0
|
value = 0
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
value = resp.ContentLength
|
value = resp.ContentLength
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *ResponseBytesSentCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheShortLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
)
|
)
|
||||||
@@ -18,11 +19,11 @@ func (this *ResponseGeneralHeaderLengthCheckpoint) IsComposed() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ResponseGeneralHeaderLengthCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *ResponseGeneralHeaderLengthCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ResponseGeneralHeaderLengthCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *ResponseGeneralHeaderLengthCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
value = false
|
value = false
|
||||||
|
|
||||||
headers := options.GetSlice("headers")
|
headers := options.GetSlice("headers")
|
||||||
@@ -42,3 +43,7 @@ func (this *ResponseGeneralHeaderLengthCheckpoint) ResponseValue(req requests.Re
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *ResponseGeneralHeaderLengthCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheMiddleLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -14,12 +15,12 @@ func (this *ResponseHeaderCheckpoint) IsRequest() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ResponseHeaderCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *ResponseHeaderCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
value = ""
|
value = ""
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ResponseHeaderCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *ResponseHeaderCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
if resp != nil && resp.Header != nil {
|
if resp != nil && resp.Header != nil {
|
||||||
value = resp.Header.Get(param)
|
value = resp.Header.Get(param)
|
||||||
} else {
|
} else {
|
||||||
@@ -27,3 +28,7 @@ func (this *ResponseHeaderCheckpoint) ResponseValue(req requests.Request, resp *
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *ResponseHeaderCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheMiddleLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -14,14 +15,18 @@ func (this *ResponseStatusCheckpoint) IsRequest() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ResponseStatusCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *ResponseStatusCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
value = 0
|
value = 0
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ResponseStatusCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *ResponseStatusCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
value = resp.StatusCode
|
value = resp.StatusCode
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *ResponseStatusCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheLongLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -10,13 +11,17 @@ type SampleRequestCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *SampleRequestCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *SampleRequestCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *SampleRequestCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *SampleRequestCheckpoint) 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() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options, ruleId)
|
return this.RequestValue(req, param, options, ruleId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *SampleRequestCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheMiddleLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -14,10 +15,14 @@ func (this *SampleResponseCheckpoint) IsRequest() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *SampleResponseCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, sysErr error, userErr error) {
|
func (this *SampleResponseCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, sysErr error, userErr error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *SampleResponseCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
|
func (this *SampleResponseCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *SampleResponseCheckpoint) CacheLife() utils.CacheLife {
|
||||||
|
return utils.CacheMiddleLife
|
||||||
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ type Request interface {
|
|||||||
WAFClose()
|
WAFClose()
|
||||||
|
|
||||||
// WAFOnAction 动作回调
|
// WAFOnAction 动作回调
|
||||||
WAFOnAction(action interface{}) (goNext bool)
|
WAFOnAction(action any) (goNext bool)
|
||||||
|
|
||||||
// WAFFingerprint 读取连接指纹
|
// WAFFingerprint 读取连接指纹
|
||||||
WAFFingerprint() []byte
|
WAFFingerprint() []byte
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ func (this *TestRequest) Format(s string) string {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *TestRequest) WAFOnAction(action interface{}) bool {
|
func (this *TestRequest) WAFOnAction(action any) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
|
|
||||||
var singleParamRegexp = regexp.MustCompile(`^\${[\w.-]+}$`)
|
var singleParamRegexp = regexp.MustCompile(`^\${[\w.-]+}$`)
|
||||||
|
|
||||||
// Rule
|
// Rule waf rule under rule set
|
||||||
type Rule struct {
|
type Rule struct {
|
||||||
Id int64
|
Id int64
|
||||||
|
|
||||||
@@ -53,7 +53,9 @@ type Rule struct {
|
|||||||
ipList *values.StringList
|
ipList *values.StringList
|
||||||
|
|
||||||
floatValue float64
|
floatValue float64
|
||||||
reg *re.Regexp
|
|
||||||
|
reg *re.Regexp
|
||||||
|
regCacheLife utils.CacheLife
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRule() *Rule {
|
func NewRule() *Rule {
|
||||||
@@ -161,6 +163,8 @@ func (this *Rule) Init() error {
|
|||||||
}
|
}
|
||||||
this.singleCheckpoint = checkpoint
|
this.singleCheckpoint = checkpoint
|
||||||
this.Priority = checkpoint.Priority()
|
this.Priority = checkpoint.Priority()
|
||||||
|
|
||||||
|
this.regCacheLife = checkpoint.CacheLife()
|
||||||
} else {
|
} else {
|
||||||
var checkpoint = checkpoints.FindCheckpoint(prefix)
|
var checkpoint = checkpoints.FindCheckpoint(prefix)
|
||||||
if checkpoint == nil {
|
if checkpoint == nil {
|
||||||
@@ -169,6 +173,8 @@ func (this *Rule) Init() error {
|
|||||||
checkpoint.Init()
|
checkpoint.Init()
|
||||||
this.singleCheckpoint = checkpoint
|
this.singleCheckpoint = checkpoint
|
||||||
this.Priority = checkpoint.Priority()
|
this.Priority = checkpoint.Priority()
|
||||||
|
|
||||||
|
this.regCacheLife = checkpoint.CacheLife()
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -186,6 +192,10 @@ func (this *Rule) Init() error {
|
|||||||
} else {
|
} else {
|
||||||
this.multipleCheckpoints[prefix] = checkpoint
|
this.multipleCheckpoints[prefix] = checkpoint
|
||||||
this.Priority = checkpoint.Priority()
|
this.Priority = checkpoint.Priority()
|
||||||
|
|
||||||
|
if this.regCacheLife <= 0 || checkpoint.CacheLife() < this.regCacheLife {
|
||||||
|
this.regCacheLife = checkpoint.CacheLife()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var checkpoint = checkpoints.FindCheckpoint(prefix)
|
var checkpoint = checkpoints.FindCheckpoint(prefix)
|
||||||
@@ -195,8 +205,11 @@ func (this *Rule) Init() error {
|
|||||||
checkpoint.Init()
|
checkpoint.Init()
|
||||||
this.multipleCheckpoints[prefix] = checkpoint
|
this.multipleCheckpoints[prefix] = checkpoint
|
||||||
this.Priority = checkpoint.Priority()
|
this.Priority = checkpoint.Priority()
|
||||||
|
|
||||||
|
this.regCacheLife = checkpoint.CacheLife()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -357,7 +370,7 @@ func (this *Rule) MatchResponse(req requests.Request, resp *requests.Response) (
|
|||||||
return this.Test(value), hasRequestBody, nil
|
return this.Test(value), hasRequestBody, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Rule) Test(value interface{}) bool {
|
func (this *Rule) Test(value any) bool {
|
||||||
// operator
|
// operator
|
||||||
switch this.Operator {
|
switch this.Operator {
|
||||||
case RuleOperatorGt:
|
case RuleOperatorGt:
|
||||||
@@ -393,7 +406,7 @@ func (this *Rule) Test(value interface{}) bool {
|
|||||||
stringList, ok := value.([]string)
|
stringList, ok := value.([]string)
|
||||||
if ok {
|
if ok {
|
||||||
for _, s := range stringList {
|
for _, s := range stringList {
|
||||||
if utils.MatchStringCache(this.reg, s) {
|
if utils.MatchStringCache(this.reg, s, this.regCacheLife) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -403,11 +416,11 @@ func (this *Rule) Test(value interface{}) bool {
|
|||||||
// bytes
|
// bytes
|
||||||
byteSlice, ok := value.([]byte)
|
byteSlice, ok := value.([]byte)
|
||||||
if ok {
|
if ok {
|
||||||
return utils.MatchBytesCache(this.reg, byteSlice)
|
return utils.MatchBytesCache(this.reg, byteSlice, this.regCacheLife)
|
||||||
}
|
}
|
||||||
|
|
||||||
// string
|
// string
|
||||||
return utils.MatchStringCache(this.reg, types.String(value))
|
return utils.MatchStringCache(this.reg, types.String(value), this.regCacheLife)
|
||||||
case RuleOperatorNotMatch, RuleOperatorWildcardNotMatch:
|
case RuleOperatorNotMatch, RuleOperatorWildcardNotMatch:
|
||||||
if value == nil {
|
if value == nil {
|
||||||
return true
|
return true
|
||||||
@@ -415,7 +428,7 @@ func (this *Rule) Test(value interface{}) bool {
|
|||||||
stringList, ok := value.([]string)
|
stringList, ok := value.([]string)
|
||||||
if ok {
|
if ok {
|
||||||
for _, s := range stringList {
|
for _, s := range stringList {
|
||||||
if utils.MatchStringCache(this.reg, s) {
|
if utils.MatchStringCache(this.reg, s, this.regCacheLife) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -425,16 +438,16 @@ func (this *Rule) Test(value interface{}) bool {
|
|||||||
// bytes
|
// bytes
|
||||||
byteSlice, ok := value.([]byte)
|
byteSlice, ok := value.([]byte)
|
||||||
if ok {
|
if ok {
|
||||||
return !utils.MatchBytesCache(this.reg, byteSlice)
|
return !utils.MatchBytesCache(this.reg, byteSlice, this.regCacheLife)
|
||||||
}
|
}
|
||||||
|
|
||||||
return !utils.MatchStringCache(this.reg, types.String(value))
|
return !utils.MatchStringCache(this.reg, types.String(value), this.regCacheLife)
|
||||||
case RuleOperatorContains:
|
case RuleOperatorContains:
|
||||||
if types.IsSlice(value) {
|
if types.IsSlice(value) {
|
||||||
_, isBytes := value.([]byte)
|
_, isBytes := value.([]byte)
|
||||||
if !isBytes {
|
if !isBytes {
|
||||||
ok := false
|
ok := false
|
||||||
lists.Each(value, func(k int, v interface{}) {
|
lists.Each(value, func(k int, v any) {
|
||||||
if types.String(v) == this.Value {
|
if types.String(v) == this.Value {
|
||||||
ok = true
|
ok = true
|
||||||
}
|
}
|
||||||
@@ -704,7 +717,7 @@ func (this *Rule) ipToInt64(ip net.IP) int64 {
|
|||||||
return int64(binary.BigEndian.Uint32(ip))
|
return int64(binary.BigEndian.Uint32(ip))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Rule) execFilter(value interface{}) interface{} {
|
func (this *Rule) execFilter(value any) any {
|
||||||
var goNext bool
|
var goNext bool
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
|||||||
@@ -3,21 +3,34 @@ package utils
|
|||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/re"
|
"github.com/TeaOSLab/EdgeNode/internal/re"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/ttlcache"
|
"github.com/TeaOSLab/EdgeNode/internal/ttlcache"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/utils/fasttime"
|
||||||
"github.com/cespare/xxhash"
|
"github.com/cespare/xxhash"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var cache = ttlcache.NewCache[int8]()
|
var cache = ttlcache.NewCache[int8]()
|
||||||
|
|
||||||
|
const (
|
||||||
|
maxCacheDataSize = 1024
|
||||||
|
)
|
||||||
|
|
||||||
|
type CacheLife = int64
|
||||||
|
|
||||||
|
const (
|
||||||
|
CacheDisabled CacheLife = 0
|
||||||
|
CacheShortLife CacheLife = 600
|
||||||
|
CacheMiddleLife CacheLife = 1800
|
||||||
|
CacheLongLife CacheLife = 7200
|
||||||
|
)
|
||||||
|
|
||||||
// MatchStringCache 正则表达式匹配字符串,并缓存结果
|
// MatchStringCache 正则表达式匹配字符串,并缓存结果
|
||||||
func MatchStringCache(regex *re.Regexp, s string) bool {
|
func MatchStringCache(regex *re.Regexp, s string, cacheLife CacheLife) bool {
|
||||||
if regex == nil {
|
if regex == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果长度超过4096,大概率是不能重用的
|
// 如果长度超过一定数量,大概率是不能重用的
|
||||||
if len(s) > 4096 {
|
if cacheLife <= 0 || len(s) > maxCacheDataSize {
|
||||||
return regex.MatchString(s)
|
return regex.MatchString(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,21 +42,21 @@ func MatchStringCache(regex *re.Regexp, s string) bool {
|
|||||||
}
|
}
|
||||||
var b = regex.MatchString(s)
|
var b = regex.MatchString(s)
|
||||||
if b {
|
if b {
|
||||||
cache.Write(key, 1, time.Now().Unix()+1800)
|
cache.Write(key, 1, fasttime.Now().Unix()+cacheLife)
|
||||||
} else {
|
} else {
|
||||||
cache.Write(key, 0, time.Now().Unix()+1800)
|
cache.Write(key, 0, fasttime.Now().Unix()+cacheLife)
|
||||||
}
|
}
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
// MatchBytesCache 正则表达式匹配字节slice,并缓存结果
|
// MatchBytesCache 正则表达式匹配字节slice,并缓存结果
|
||||||
func MatchBytesCache(regex *re.Regexp, byteSlice []byte) bool {
|
func MatchBytesCache(regex *re.Regexp, byteSlice []byte, cacheLife CacheLife) bool {
|
||||||
if regex == nil {
|
if regex == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果长度超过4096,大概率是不能重用的
|
// 如果长度超过一定数量,大概率是不能重用的
|
||||||
if len(byteSlice) > 4096 {
|
if cacheLife <= 0 || len(byteSlice) > maxCacheDataSize {
|
||||||
return regex.Match(byteSlice)
|
return regex.Match(byteSlice)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,9 +71,9 @@ func MatchBytesCache(regex *re.Regexp, byteSlice []byte) bool {
|
|||||||
}
|
}
|
||||||
var b = regex.Match(byteSlice)
|
var b = regex.Match(byteSlice)
|
||||||
if b {
|
if b {
|
||||||
cache.Write(key, 1, time.Now().Unix()+1800)
|
cache.Write(key, 1, fasttime.Now().Unix()+cacheLife)
|
||||||
} else {
|
} else {
|
||||||
cache.Write(key, 0, time.Now().Unix()+1800)
|
cache.Write(key, 0, fasttime.Now().Unix()+cacheLife)
|
||||||
}
|
}
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,16 +14,16 @@ import (
|
|||||||
|
|
||||||
func TestMatchStringCache(t *testing.T) {
|
func TestMatchStringCache(t *testing.T) {
|
||||||
regex := re.MustCompile(`\d+`)
|
regex := re.MustCompile(`\d+`)
|
||||||
t.Log(utils.MatchStringCache(regex, "123"))
|
t.Log(utils.MatchStringCache(regex, "123", utils.CacheShortLife))
|
||||||
t.Log(utils.MatchStringCache(regex, "123"))
|
t.Log(utils.MatchStringCache(regex, "123", utils.CacheShortLife))
|
||||||
t.Log(utils.MatchStringCache(regex, "123"))
|
t.Log(utils.MatchStringCache(regex, "123", utils.CacheShortLife))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMatchBytesCache(t *testing.T) {
|
func TestMatchBytesCache(t *testing.T) {
|
||||||
regex := re.MustCompile(`\d+`)
|
regex := re.MustCompile(`\d+`)
|
||||||
t.Log(utils.MatchBytesCache(regex, []byte("123")))
|
t.Log(utils.MatchBytesCache(regex, []byte("123"), utils.CacheShortLife))
|
||||||
t.Log(utils.MatchBytesCache(regex, []byte("123")))
|
t.Log(utils.MatchBytesCache(regex, []byte("123"), utils.CacheShortLife))
|
||||||
t.Log(utils.MatchBytesCache(regex, []byte("123")))
|
t.Log(utils.MatchBytesCache(regex, []byte("123"), utils.CacheShortLife))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMatchRemoteCache(t *testing.T) {
|
func TestMatchRemoteCache(t *testing.T) {
|
||||||
@@ -53,13 +53,13 @@ func TestMatchBytesCache_WithoutCache(t *testing.T) {
|
|||||||
func BenchmarkMatchStringCache(b *testing.B) {
|
func BenchmarkMatchStringCache(b *testing.B) {
|
||||||
runtime.GOMAXPROCS(1)
|
runtime.GOMAXPROCS(1)
|
||||||
|
|
||||||
var data = strings.Repeat("HELLO", 512)
|
var data = strings.Repeat("HELLO", 128)
|
||||||
var regex = re.MustCompile(`(?iU)\b(eval|system|exec|execute|passthru|shell_exec|phpinfo)\b`)
|
var regex = re.MustCompile(`(?iU)\b(eval|system|exec|execute|passthru|shell_exec|phpinfo)\b`)
|
||||||
//b.Log(regex.Keywords())
|
//b.Log(regex.Keywords())
|
||||||
_ = utils.MatchStringCache(regex, data)
|
_ = utils.MatchStringCache(regex, data, utils.CacheShortLife)
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = utils.MatchStringCache(regex, data)
|
_ = utils.MatchStringCache(regex, data, utils.CacheShortLife)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user