diff --git a/internal/waf/checkpoints/request_all.go b/internal/waf/checkpoints/request_all.go index fc76b97..b347568 100644 --- a/internal/waf/checkpoints/request_all.go +++ b/internal/waf/checkpoints/request_all.go @@ -2,6 +2,7 @@ package checkpoints import ( "github.com/TeaOSLab/EdgeNode/internal/waf/requests" + "github.com/TeaOSLab/EdgeNode/internal/waf/utils" "github.com/iwind/TeaGo/maps" ) @@ -28,7 +29,7 @@ func (this *RequestAllCheckpoint) RequestValue(req requests.Request, param strin var bodyData = req.WAFGetCacheBody() if len(bodyData) == 0 { - data, err := req.WAFReadBody(int64(32 * 1024 * 1024)) // read 32m bytes + data, err := req.WAFReadBody(utils.MaxBodySize) // read body if err != nil { return "", err, nil } diff --git a/internal/waf/checkpoints/request_body.go b/internal/waf/checkpoints/request_body.go index ce00565..90884d6 100644 --- a/internal/waf/checkpoints/request_body.go +++ b/internal/waf/checkpoints/request_body.go @@ -2,6 +2,7 @@ package checkpoints import ( "github.com/TeaOSLab/EdgeNode/internal/waf/requests" + "github.com/TeaOSLab/EdgeNode/internal/waf/utils" "github.com/iwind/TeaGo/maps" ) @@ -23,7 +24,7 @@ func (this *RequestBodyCheckpoint) RequestValue(req requests.Request, param stri var bodyData = req.WAFGetCacheBody() if len(bodyData) == 0 { - data, err := req.WAFReadBody(int64(32 * 1024 * 1024)) // read 32m bytes + data, err := req.WAFReadBody(utils.MaxBodySize) // read body if err != nil { return "", err, nil } diff --git a/internal/waf/checkpoints/request_form_arg.go b/internal/waf/checkpoints/request_form_arg.go index 9ebc929..8cc3a37 100644 --- a/internal/waf/checkpoints/request_form_arg.go +++ b/internal/waf/checkpoints/request_form_arg.go @@ -2,6 +2,7 @@ package checkpoints import ( "github.com/TeaOSLab/EdgeNode/internal/waf/requests" + "github.com/TeaOSLab/EdgeNode/internal/waf/utils" "github.com/iwind/TeaGo/maps" "net/url" ) @@ -24,7 +25,7 @@ func (this *RequestFormArgCheckpoint) RequestValue(req requests.Request, param s var bodyData = req.WAFGetCacheBody() if len(bodyData) == 0 { - data, err := req.WAFReadBody(int64(32 * 1024 * 1024)) // read 32m bytes + data, err := req.WAFReadBody(utils.MaxBodySize) // read body if err != nil { return "", err, nil } diff --git a/internal/waf/checkpoints/request_json_arg.go b/internal/waf/checkpoints/request_json_arg.go index 341db2d..578ab18 100644 --- a/internal/waf/checkpoints/request_json_arg.go +++ b/internal/waf/checkpoints/request_json_arg.go @@ -4,6 +4,7 @@ import ( "encoding/json" "github.com/TeaOSLab/EdgeNode/internal/utils" "github.com/TeaOSLab/EdgeNode/internal/waf/requests" + wafutils "github.com/TeaOSLab/EdgeNode/internal/waf/utils" "github.com/iwind/TeaGo/maps" "strings" ) @@ -16,7 +17,7 @@ type RequestJSONArgCheckpoint struct { func (this *RequestJSONArgCheckpoint) RequestValue(req requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) { var bodyData = req.WAFGetCacheBody() if len(bodyData) == 0 { - data, err := req.WAFReadBody(int64(32 * 1024 * 1024)) // read 32m bytes + data, err := req.WAFReadBody(wafutils.MaxBodySize) // read body if err != nil { return "", err, nil } diff --git a/internal/waf/checkpoints/request_upload.go b/internal/waf/checkpoints/request_upload.go index 9608f0e..474bb81 100644 --- a/internal/waf/checkpoints/request_upload.go +++ b/internal/waf/checkpoints/request_upload.go @@ -3,6 +3,7 @@ package checkpoints import ( "bytes" "github.com/TeaOSLab/EdgeNode/internal/waf/requests" + "github.com/TeaOSLab/EdgeNode/internal/waf/utils" "github.com/iwind/TeaGo/lists" "github.com/iwind/TeaGo/maps" "io/ioutil" @@ -38,7 +39,7 @@ func (this *RequestUploadCheckpoint) RequestValue(req requests.Request, param st if req.WAFRaw().MultipartForm == nil { var bodyData = req.WAFGetCacheBody() if len(bodyData) == 0 { - data, err := req.WAFReadBody(32 * 1024 * 1024) + data, err := req.WAFReadBody(utils.MaxBodySize) if err != nil { sysErr = err return @@ -51,7 +52,7 @@ func (this *RequestUploadCheckpoint) RequestValue(req requests.Request, param st oldBody := req.WAFRaw().Body req.WAFRaw().Body = ioutil.NopCloser(bytes.NewBuffer(bodyData)) - err := req.WAFRaw().ParseMultipartForm(32 * 1024 * 1024) + err := req.WAFRaw().ParseMultipartForm(utils.MaxBodySize) // 还原 req.WAFRaw().Body = oldBody diff --git a/internal/waf/utils/consts.go b/internal/waf/utils/consts.go new file mode 100644 index 0000000..a291048 --- /dev/null +++ b/internal/waf/utils/consts.go @@ -0,0 +1,9 @@ +// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. + +package utils + +import "github.com/TeaOSLab/EdgeNode/internal/utils/sizes" + +const ( + MaxBodySize = 4 * sizes.M +)