mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-10 20:50:25 +08:00
[WAF]规则中增加请求Header长度限制和响应Header长度限制
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
package teaconst
|
package teaconst
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version = "0.0.1"
|
Version = "0.0.2"
|
||||||
|
|
||||||
ProductName = "Edge Node"
|
ProductName = "Edge Node"
|
||||||
ProcessName = "edge-node"
|
ProcessName = "edge-node"
|
||||||
|
|||||||
@@ -132,7 +132,9 @@ func (this *HTTPListener) handleHTTP(rawWriter http.ResponseWriter, rawReq *http
|
|||||||
mismatchAction := httpAllConfig.DomainMismatchAction
|
mismatchAction := httpAllConfig.DomainMismatchAction
|
||||||
if mismatchAction != nil && mismatchAction.Code == "page" {
|
if mismatchAction != nil && mismatchAction.Code == "page" {
|
||||||
if mismatchAction.Options != nil {
|
if mismatchAction.Options != nil {
|
||||||
http.Error(rawWriter, mismatchAction.Options.GetString("contentHTML"), mismatchAction.Options.GetInt("statusCode"))
|
rawWriter.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
|
rawWriter.WriteHeader(mismatchAction.Options.GetInt("statusCode"))
|
||||||
|
_, _ = rawWriter.Write([]byte(mismatchAction.Options.GetString("contentHTML")))
|
||||||
} else {
|
} else {
|
||||||
http.Error(rawWriter, "404 page not found: '"+rawReq.URL.String()+"'", http.StatusNotFound)
|
http.Error(rawWriter, "404 page not found: '"+rawReq.URL.String()+"'", http.StatusNotFound)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ func (this *CCCheckpoint) Start() {
|
|||||||
this.grid = grids.NewGrid(32, grids.NewLimitCountOpt(1000_0000))
|
this.grid = grids.NewGrid(32, grids.NewLimitCountOpt(1000_0000))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CCCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *CCCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
value = 0
|
value = 0
|
||||||
|
|
||||||
if this.grid == nil {
|
if this.grid == nil {
|
||||||
@@ -121,7 +121,7 @@ func (this *CCCheckpoint) RequestValue(req *requests.Request, param string, opti
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CCCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *CCCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if this.IsRequest() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options)
|
return this.RequestValue(req, param, options)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ func (this *Checkpoint) IsRequest() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *Checkpoint) IsComposed() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (this *Checkpoint) ParamOptions() *ParamOptions {
|
func (this *Checkpoint) ParamOptions() *ParamOptions {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Check Point
|
// Check Point
|
||||||
@@ -12,11 +13,14 @@ type CheckpointInterface interface {
|
|||||||
// is request?
|
// is request?
|
||||||
IsRequest() bool
|
IsRequest() bool
|
||||||
|
|
||||||
|
// is composed?
|
||||||
|
IsComposed() bool
|
||||||
|
|
||||||
// get request value
|
// get request value
|
||||||
RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error)
|
RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error)
|
||||||
|
|
||||||
// get response value
|
// get response value
|
||||||
ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error)
|
ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error)
|
||||||
|
|
||||||
// param option list
|
// param option list
|
||||||
ParamOptions() *ParamOptions
|
ParamOptions() *ParamOptions
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ${requestAll}
|
// ${requestAll}
|
||||||
@@ -9,7 +10,7 @@ type RequestAllCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestAllCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestAllCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
valueBytes := []byte{}
|
valueBytes := []byte{}
|
||||||
if len(req.RequestURI) > 0 {
|
if len(req.RequestURI) > 0 {
|
||||||
valueBytes = append(valueBytes, req.RequestURI...)
|
valueBytes = append(valueBytes, req.RequestURI...)
|
||||||
@@ -37,7 +38,7 @@ func (this *RequestAllCheckpoint) RequestValue(req *requests.Request, param stri
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestAllCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestAllCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
value = ""
|
value = ""
|
||||||
if this.IsRequest() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options)
|
return this.RequestValue(req, param, options)
|
||||||
|
|||||||
@@ -2,17 +2,18 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RequestArgCheckpoint struct {
|
type RequestArgCheckpoint struct {
|
||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestArgCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestArgCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
return req.URL.Query().Get(param), nil, nil
|
return req.URL.Query().Get(param), nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestArgCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestArgCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if this.IsRequest() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options)
|
return this.RequestValue(req, param, options)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,18 +2,19 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RequestArgsCheckpoint struct {
|
type RequestArgsCheckpoint struct {
|
||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestArgsCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestArgsCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
value = req.URL.RawQuery
|
value = req.URL.RawQuery
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestArgsCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestArgsCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if this.IsRequest() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options)
|
return this.RequestValue(req, param, options)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ${requestBody}
|
// ${requestBody}
|
||||||
@@ -9,7 +10,7 @@ type RequestBodyCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestBodyCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestBodyCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if req.Body == nil {
|
if req.Body == nil {
|
||||||
value = ""
|
value = ""
|
||||||
return
|
return
|
||||||
@@ -28,7 +29,7 @@ func (this *RequestBodyCheckpoint) RequestValue(req *requests.Request, param str
|
|||||||
return req.BodyData, nil, nil
|
return req.BodyData, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestBodyCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestBodyCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if this.IsRequest() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options)
|
return this.RequestValue(req, param, options)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,18 +2,19 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RequestContentTypeCheckpoint struct {
|
type RequestContentTypeCheckpoint struct {
|
||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestContentTypeCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestContentTypeCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
value = req.Header.Get("Content-Type")
|
value = req.Header.Get("Content-Type")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestContentTypeCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestContentTypeCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if this.IsRequest() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options)
|
return this.RequestValue(req, param, options)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,14 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RequestCookieCheckpoint struct {
|
type RequestCookieCheckpoint struct {
|
||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestCookieCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestCookieCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
cookie, err := req.Cookie(param)
|
cookie, err := req.Cookie(param)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
value = ""
|
value = ""
|
||||||
@@ -19,7 +20,7 @@ func (this *RequestCookieCheckpoint) RequestValue(req *requests.Request, param s
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestCookieCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestCookieCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if this.IsRequest() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options)
|
return this.RequestValue(req, param, options)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -10,7 +11,7 @@ type RequestCookiesCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestCookiesCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestCookiesCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
var cookies = []string{}
|
var cookies = []string{}
|
||||||
for _, cookie := range req.Cookies() {
|
for _, cookie := range req.Cookies() {
|
||||||
cookies = append(cookies, url.QueryEscape(cookie.Name)+"="+url.QueryEscape(cookie.Value))
|
cookies = append(cookies, url.QueryEscape(cookie.Name)+"="+url.QueryEscape(cookie.Value))
|
||||||
@@ -19,7 +20,7 @@ func (this *RequestCookiesCheckpoint) RequestValue(req *requests.Request, param
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestCookiesCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestCookiesCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if this.IsRequest() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options)
|
return this.RequestValue(req, param, options)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
"net/url"
|
"net/url"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -10,7 +11,7 @@ type RequestFormArgCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestFormArgCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestFormArgCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if req.Body == nil {
|
if req.Body == nil {
|
||||||
value = ""
|
value = ""
|
||||||
return
|
return
|
||||||
@@ -31,7 +32,7 @@ func (this *RequestFormArgCheckpoint) RequestValue(req *requests.Request, param
|
|||||||
return values.Get(param), nil, nil
|
return values.Get(param), nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestFormArgCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestFormArgCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if this.IsRequest() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options)
|
return this.RequestValue(req, param, options)
|
||||||
}
|
}
|
||||||
|
|||||||
40
internal/waf/checkpoints/request_general_header_length.go
Normal file
40
internal/waf/checkpoints/request_general_header_length.go
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package checkpoints
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
"github.com/iwind/TeaGo/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RequestGeneralHeaderLengthCheckpoint struct {
|
||||||
|
Checkpoint
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RequestGeneralHeaderLengthCheckpoint) IsComposed() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RequestGeneralHeaderLengthCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
|
value = false
|
||||||
|
|
||||||
|
headers := options.GetSlice("headers")
|
||||||
|
if len(headers) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
length := options.GetInt("length")
|
||||||
|
|
||||||
|
for _, header := range headers {
|
||||||
|
v := req.Header.Get(types.String(header))
|
||||||
|
if len(v) > length {
|
||||||
|
value = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RequestGeneralHeaderLengthCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,7 +10,7 @@ type RequestHeaderCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestHeaderCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestHeaderCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
v, found := req.Header[param]
|
v, found := req.Header[param]
|
||||||
if !found {
|
if !found {
|
||||||
value = ""
|
value = ""
|
||||||
@@ -19,7 +20,7 @@ func (this *RequestHeaderCheckpoint) RequestValue(req *requests.Request, param s
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestHeaderCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestHeaderCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if this.IsRequest() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options)
|
return this.RequestValue(req, param, options)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -10,7 +11,7 @@ type RequestHeadersCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestHeadersCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestHeadersCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
var headers = []string{}
|
var headers = []string{}
|
||||||
for k, v := range req.Header {
|
for k, v := range req.Header {
|
||||||
for _, subV := range v {
|
for _, subV := range v {
|
||||||
@@ -22,7 +23,7 @@ func (this *RequestHeadersCheckpoint) RequestValue(req *requests.Request, param
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestHeadersCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestHeadersCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if this.IsRequest() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options)
|
return this.RequestValue(req, param, options)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,18 +2,19 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RequestHostCheckpoint struct {
|
type RequestHostCheckpoint struct {
|
||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestHostCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestHostCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
value = req.Host
|
value = req.Host
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestHostCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestHostCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if this.IsRequest() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options)
|
return this.RequestValue(req, param, options)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -12,7 +13,7 @@ type RequestJSONArgCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestJSONArgCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestJSONArgCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if len(req.BodyData) == 0 {
|
if len(req.BodyData) == 0 {
|
||||||
data, err := req.ReadBody(int64(32 * 1024 * 1024)) // read 32m bytes
|
data, err := req.ReadBody(int64(32 * 1024 * 1024)) // read 32m bytes
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -36,7 +37,7 @@ func (this *RequestJSONArgCheckpoint) RequestValue(req *requests.Request, param
|
|||||||
return "", nil, nil
|
return "", nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestJSONArgCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestJSONArgCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if this.IsRequest() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options)
|
return this.RequestValue(req, param, options)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,18 +2,19 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RequestLengthCheckpoint struct {
|
type RequestLengthCheckpoint struct {
|
||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestLengthCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestLengthCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
value = req.ContentLength
|
value = req.ContentLength
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestLengthCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestLengthCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if this.IsRequest() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options)
|
return this.RequestValue(req, param, options)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,18 +2,19 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RequestMethodCheckpoint struct {
|
type RequestMethodCheckpoint struct {
|
||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestMethodCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestMethodCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
value = req.Method
|
value = req.Method
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestMethodCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestMethodCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if this.IsRequest() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options)
|
return this.RequestValue(req, param, options)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,17 +2,18 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RequestPathCheckpoint struct {
|
type RequestPathCheckpoint struct {
|
||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestPathCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestPathCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
return req.URL.Path, nil, nil
|
return req.URL.Path, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestPathCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestPathCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if this.IsRequest() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options)
|
return this.RequestValue(req, param, options)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,18 +2,19 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RequestProtoCheckpoint struct {
|
type RequestProtoCheckpoint struct {
|
||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestProtoCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestProtoCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
value = req.Proto
|
value = req.Proto
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestProtoCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestProtoCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if this.IsRequest() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options)
|
return this.RequestValue(req, param, options)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
"net"
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,7 +10,7 @@ type RequestRawRemoteAddrCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestRawRemoteAddrCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestRawRemoteAddrCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
host, _, err := net.SplitHostPort(req.RemoteAddr)
|
host, _, err := net.SplitHostPort(req.RemoteAddr)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
value = host
|
value = host
|
||||||
@@ -19,7 +20,7 @@ func (this *RequestRawRemoteAddrCheckpoint) RequestValue(req *requests.Request,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestRawRemoteAddrCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestRawRemoteAddrCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if this.IsRequest() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options)
|
return this.RequestValue(req, param, options)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,18 +2,19 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RequestRefererCheckpoint struct {
|
type RequestRefererCheckpoint struct {
|
||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestRefererCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestRefererCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
value = req.Referer()
|
value = req.Referer()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestRefererCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestRefererCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if this.IsRequest() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options)
|
return this.RequestValue(req, param, options)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -10,7 +11,7 @@ type RequestRemoteAddrCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestRemoteAddrCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestRemoteAddrCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
// X-Forwarded-For
|
// X-Forwarded-For
|
||||||
forwardedFor := req.Header.Get("X-Forwarded-For")
|
forwardedFor := req.Header.Get("X-Forwarded-For")
|
||||||
if len(forwardedFor) > 0 {
|
if len(forwardedFor) > 0 {
|
||||||
@@ -51,7 +52,7 @@ func (this *RequestRemoteAddrCheckpoint) RequestValue(req *requests.Request, par
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestRemoteAddrCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestRemoteAddrCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if this.IsRequest() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options)
|
return this.RequestValue(req, param, options)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
"net"
|
"net"
|
||||||
)
|
)
|
||||||
@@ -10,7 +11,7 @@ type RequestRemotePortCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestRemotePortCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestRemotePortCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
_, port, err := net.SplitHostPort(req.RemoteAddr)
|
_, port, err := net.SplitHostPort(req.RemoteAddr)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
value = types.Int(port)
|
value = types.Int(port)
|
||||||
@@ -20,7 +21,7 @@ func (this *RequestRemotePortCheckpoint) RequestValue(req *requests.Request, par
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestRemotePortCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestRemotePortCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if this.IsRequest() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options)
|
return this.RequestValue(req, param, options)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,14 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RequestRemoteUserCheckpoint struct {
|
type RequestRemoteUserCheckpoint struct {
|
||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestRemoteUserCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestRemoteUserCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
username, _, ok := req.BasicAuth()
|
username, _, ok := req.BasicAuth()
|
||||||
if !ok {
|
if !ok {
|
||||||
value = ""
|
value = ""
|
||||||
@@ -18,7 +19,7 @@ func (this *RequestRemoteUserCheckpoint) RequestValue(req *requests.Request, par
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestRemoteUserCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestRemoteUserCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if this.IsRequest() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options)
|
return this.RequestValue(req, param, options)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,18 +2,19 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RequestSchemeCheckpoint struct {
|
type RequestSchemeCheckpoint struct {
|
||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestSchemeCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestSchemeCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
value = req.URL.Scheme
|
value = req.URL.Scheme
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestSchemeCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestSchemeCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if this.IsRequest() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options)
|
return this.RequestValue(req, param, options)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
"github.com/iwind/TeaGo/lists"
|
"github.com/iwind/TeaGo/lists"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -15,7 +16,7 @@ type RequestUploadCheckpoint struct {
|
|||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestUploadCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestUploadCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
value = ""
|
value = ""
|
||||||
if param == "minSize" || param == "maxSize" {
|
if param == "minSize" || param == "maxSize" {
|
||||||
value = 0
|
value = 0
|
||||||
@@ -112,7 +113,7 @@ func (this *RequestUploadCheckpoint) RequestValue(req *requests.Request, param s
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestUploadCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestUploadCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if this.IsRequest() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options)
|
return this.RequestValue(req, param, options)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,14 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RequestURICheckpoint struct {
|
type RequestURICheckpoint struct {
|
||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestURICheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestURICheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if len(req.RequestURI) > 0 {
|
if len(req.RequestURI) > 0 {
|
||||||
value = req.RequestURI
|
value = req.RequestURI
|
||||||
} else if req.URL != nil {
|
} else if req.URL != nil {
|
||||||
@@ -17,7 +18,7 @@ func (this *RequestURICheckpoint) RequestValue(req *requests.Request, param stri
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestURICheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestURICheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if this.IsRequest() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options)
|
return this.RequestValue(req, param, options)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,18 +2,19 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RequestUserAgentCheckpoint struct {
|
type RequestUserAgentCheckpoint struct {
|
||||||
Checkpoint
|
Checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestUserAgentCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestUserAgentCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
value = req.UserAgent()
|
value = req.UserAgent()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RequestUserAgentCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *RequestUserAgentCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if this.IsRequest() {
|
if this.IsRequest() {
|
||||||
return this.RequestValue(req, param, options)
|
return this.RequestValue(req, param, options)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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/iwind/TeaGo/maps"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,12 +16,12 @@ func (this *ResponseBodyCheckpoint) IsRequest() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ResponseBodyCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *ResponseBodyCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
value = ""
|
value = ""
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ResponseBodyCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *ResponseBodyCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
value = ""
|
value = ""
|
||||||
if resp != nil && resp.Body != nil {
|
if resp != nil && resp.Body != nil {
|
||||||
if len(resp.BodyData) > 0 {
|
if len(resp.BodyData) > 0 {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ${bytesSent}
|
// ${bytesSent}
|
||||||
@@ -13,12 +14,12 @@ func (this *ResponseBytesSentCheckpoint) IsRequest() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ResponseBytesSentCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *ResponseBytesSentCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
value = 0
|
value = 0
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ResponseBytesSentCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *ResponseBytesSentCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
value = 0
|
value = 0
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
value = resp.ContentLength
|
value = resp.ContentLength
|
||||||
|
|||||||
45
internal/waf/checkpoints/response_general_header_length.go
Normal file
45
internal/waf/checkpoints/response_general_header_length.go
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package checkpoints
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
"github.com/iwind/TeaGo/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ResponseGeneralHeaderLengthCheckpoint struct {
|
||||||
|
Checkpoint
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ResponseGeneralHeaderLengthCheckpoint) IsRequest() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ResponseGeneralHeaderLengthCheckpoint) IsComposed() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ResponseGeneralHeaderLengthCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ResponseGeneralHeaderLengthCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
|
value = false
|
||||||
|
|
||||||
|
headers := options.GetSlice("headers")
|
||||||
|
if len(headers) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
length := options.GetInt("length")
|
||||||
|
|
||||||
|
for _, header := range headers {
|
||||||
|
v := req.Header.Get(types.String(header))
|
||||||
|
if len(v) > length {
|
||||||
|
value = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ${responseHeader.arg}
|
// ${responseHeader.arg}
|
||||||
@@ -13,12 +14,12 @@ func (this *ResponseHeaderCheckpoint) IsRequest() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ResponseHeaderCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *ResponseHeaderCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
value = ""
|
value = ""
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ResponseHeaderCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *ResponseHeaderCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, 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 {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package checkpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ${bytesSent}
|
// ${bytesSent}
|
||||||
@@ -13,12 +14,12 @@ func (this *ResponseStatusCheckpoint) IsRequest() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ResponseStatusCheckpoint) RequestValue(req *requests.Request, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *ResponseStatusCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
value = 0
|
value = 0
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ResponseStatusCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]interface{}) (value interface{}, sysErr error, userErr error) {
|
func (this *ResponseStatusCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
value = resp.StatusCode
|
value = resp.StatusCode
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,13 @@ package checkpoints
|
|||||||
|
|
||||||
// all check points list
|
// all check points list
|
||||||
var AllCheckpoints = []*CheckpointDefinition{
|
var AllCheckpoints = []*CheckpointDefinition{
|
||||||
|
{
|
||||||
|
Name: "通用请求Header长度限制",
|
||||||
|
Prefix: "requestGeneralHeaderLength",
|
||||||
|
Description: "通用Header比如Cache-Control、Accept之类的长度限制,防止缓冲区溢出攻击",
|
||||||
|
HasParams: false,
|
||||||
|
Instance: new(RequestGeneralHeaderLengthCheckpoint),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "客户端地址(IP)",
|
Name: "客户端地址(IP)",
|
||||||
Prefix: "remoteAddr",
|
Prefix: "remoteAddr",
|
||||||
@@ -184,6 +191,13 @@ var AllCheckpoints = []*CheckpointDefinition{
|
|||||||
HasParams: true,
|
HasParams: true,
|
||||||
Instance: new(CCCheckpoint),
|
Instance: new(CCCheckpoint),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "通用响应Header长度限制",
|
||||||
|
Prefix: "responseGeneralHeaderLength",
|
||||||
|
Description: "通用Header比如Cache-Control、Accept之类的长度限制,防止缓冲区溢出攻击",
|
||||||
|
HasParams: false,
|
||||||
|
Instance: new(ResponseGeneralHeaderLengthCheckpoint),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "响应状态码",
|
Name: "响应状态码",
|
||||||
Prefix: "status",
|
Prefix: "status",
|
||||||
|
|||||||
@@ -186,6 +186,12 @@ func (this *Rule) MatchRequest(req *requests.Request) (b bool, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if is composed checkpoint, we just returns true or false
|
||||||
|
if this.singleCheckpoint.IsComposed() {
|
||||||
|
return types.Bool(value), nil
|
||||||
|
}
|
||||||
|
|
||||||
return this.Test(value), nil
|
return this.Test(value), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,6 +241,12 @@ func (this *Rule) MatchResponse(req *requests.Request, resp *requests.Response)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if is composed checkpoint, we just returns true or false
|
||||||
|
if this.singleCheckpoint.IsComposed() {
|
||||||
|
return types.Bool(value), nil
|
||||||
|
}
|
||||||
|
|
||||||
return this.Test(value), nil
|
return this.Test(value), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user