github.com/TeaOSLab/EdgeNode@v1.3.8/internal/waf/checkpoints/response_general_header_length.go (about)

     1  package checkpoints
     2  
     3  import (
     4  	"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
     5  	"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
     6  	"github.com/iwind/TeaGo/maps"
     7  	"github.com/iwind/TeaGo/types"
     8  )
     9  
    10  type ResponseGeneralHeaderLengthCheckpoint struct {
    11  	Checkpoint
    12  }
    13  
    14  func (this *ResponseGeneralHeaderLengthCheckpoint) IsRequest() bool {
    15  	return false
    16  }
    17  
    18  func (this *ResponseGeneralHeaderLengthCheckpoint) IsComposed() bool {
    19  	return true
    20  }
    21  
    22  func (this *ResponseGeneralHeaderLengthCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
    23  	return
    24  }
    25  
    26  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) {
    27  	value = false
    28  
    29  	headers := options.GetSlice("headers")
    30  	if len(headers) == 0 {
    31  		return
    32  	}
    33  
    34  	length := options.GetInt("length")
    35  
    36  	for _, header := range headers {
    37  		v := req.WAFRaw().Header.Get(types.String(header))
    38  		if len(v) > length {
    39  			value = true
    40  			break
    41  		}
    42  	}
    43  
    44  	return
    45  }
    46  
    47  func (this *ResponseGeneralHeaderLengthCheckpoint) CacheLife() utils.CacheLife {
    48  	return utils.CacheMiddleLife
    49  }