diff --git a/http/interceptor.go b/http/interceptor.go index 9cbf3d6a3..936e686ea 100644 --- a/http/interceptor.go +++ b/http/interceptor.go @@ -48,13 +48,13 @@ func (i *rwInterceptor) Write(b []byte) (int, error) { i.WriteHeader(http.StatusOK) } - if i.tx.Interrupted() { + if i.tx.IsInterrupted() { // if there is an interruption it must be from phase 4 and hence // we won't write anything to either the body or the buffer. return 0, nil } - if i.tx.ResponseBodyAccessible() { + if i.tx.IsResponseBodyAccessible() { // we only buffer the response body if we are going to access // to it, otherwise we just send it to the response writer. return i.tx.ResponseBodyWriter().Write(b) @@ -85,13 +85,13 @@ func wrap(w http.ResponseWriter, r *http.Request, tx types.Transaction) ( responseProcessor := func(tx types.Transaction, r *http.Request) error { // We look for interruptions determined at phase 4 (response headers) // as body hasn't being analized yet. - if tx.Interrupted() { + if tx.IsInterrupted() { // phase 4 interruption stops execution w.WriteHeader(i.statusCode) return nil } - if tx.ResponseBodyAccessible() && tx.IsProcessableResponseBody() { + if tx.IsResponseBodyAccessible() && tx.IsResponseBodyProcessable() { if it, err := tx.ProcessResponseBody(); err != nil { w.WriteHeader(http.StatusInternalServerError) return err diff --git a/http/middleware.go b/http/middleware.go index 907184165..6ad56397e 100644 --- a/http/middleware.go +++ b/http/middleware.go @@ -57,7 +57,7 @@ func processRequest(tx types.Transaction, req *http.Request) (*types.Interruptio return in, nil } - if tx.RequestBodyAccessible() { + if tx.IsRequestBodyAccessible() { // We only do body buffering if the transaction requires request // body inspection, otherwise we just let the request follow its // regular flow. diff --git a/internal/corazawaf/transaction.go b/internal/corazawaf/transaction.go index 9bc36f4ca..a49d14897 100644 --- a/internal/corazawaf/transaction.go +++ b/internal/corazawaf/transaction.go @@ -844,12 +844,12 @@ func (tx *Transaction) ProcessResponseHeaders(code int, proto string) *types.Int return tx.interruption } -// IsProcessableResponseBody returns true if the response body meets the +// IsResponseBodyProcessable returns true if the response body meets the // criteria to be processed, response headers must be set before this. // The content-type response header must be in the SecResponseBodyMimeType // This is used by webservers to choose whether to stream response buffers // directly to the client or write them to Coraza's buffer. -func (tx *Transaction) IsProcessableResponseBody() bool { +func (tx *Transaction) IsResponseBodyProcessable() bool { // TODO add more validations ct := tx.variables.responseContentType.String() return stringsutil.InSlice(ct, tx.WAF.ResponseBodyMimeTypes) @@ -870,7 +870,7 @@ func (tx *Transaction) ProcessResponseBody() (*types.Interruption, error) { if tx.RuleEngine == types.RuleEngineOff { return tx.interruption, nil } - if !tx.ResponseBodyAccess || !tx.IsProcessableResponseBody() { + if !tx.ResponseBodyAccess || !tx.IsResponseBodyProcessable() { tx.WAF.Logger.Debug("[%s] Skipping response body processing (Access: %t)", tx.id, tx.ResponseBodyAccess) tx.WAF.Rules.Eval(types.PhaseResponseBody, tx) return tx.interruption, nil @@ -944,18 +944,18 @@ func (tx *Transaction) IsRuleEngineOff() bool { return tx.RuleEngine == types.RuleEngineOff } -// RequestBodyAccessible will return true if RequestBody access has been enabled by RequestBodyAccess -func (tx *Transaction) RequestBodyAccessible() bool { +// IsRequestBodyAccessible will return true if RequestBody access has been enabled by RequestBodyAccess +func (tx *Transaction) IsRequestBodyAccessible() bool { return tx.RequestBodyAccess } -// ResponseBodyAccessible will return true if ResponseBody access has been enabled by ResponseBodyAccess -func (tx *Transaction) ResponseBodyAccessible() bool { +// IsResponseBodyAccessible will return true if ResponseBody access has been enabled by ResponseBodyAccess +func (tx *Transaction) IsResponseBodyAccessible() bool { return tx.ResponseBodyAccess } -// Interrupted will return true if the transaction was interrupted -func (tx *Transaction) Interrupted() bool { +// IsInterrupted will return true if the transaction was interrupted +func (tx *Transaction) IsInterrupted() bool { return tx.interruption != nil } @@ -1079,7 +1079,7 @@ func (tx *Transaction) Close() error { errs = append(errs, err) } - tx.WAF.Logger.Debug("[%s] Transaction finished, disrupted: %t", tx.id, tx.Interrupted()) + tx.WAF.Logger.Debug("[%s] Transaction finished, disrupted: %t", tx.id, tx.IsInterrupted()) switch { case len(errs) == 0: diff --git a/internal/seclang/rules_test.go b/internal/seclang/rules_test.go index c59ea2ec1..b4094a2b4 100644 --- a/internal/seclang/rules_test.go +++ b/internal/seclang/rules_test.go @@ -87,7 +87,7 @@ func TestSecMarkers(t *testing.T) { tx := waf.NewTransaction() defer tx.ProcessLogging() tx.ProcessRequestHeaders() - if tx.Interrupted() { + if tx.IsInterrupted() { t.Error("transaction failed to skipAfter") } interruption, err := tx.ProcessRequestBody() @@ -317,7 +317,7 @@ func TestTxIssue147(t *testing.T) { tx.ResponseBodyAccess = true // we need a content-type header tx.AddResponseHeader("Content-Type", "text/html") - if tx.IsProcessableResponseBody() { + if tx.IsResponseBodyProcessable() { if _, err := tx.ResponseBodyBuffer.Write([]byte("#!/usr/bin/python")); err != nil { t.Error(err) } diff --git a/types/transaction.go b/types/transaction.go index f247ed260..0dfd3c071 100644 --- a/types/transaction.go +++ b/types/transaction.go @@ -106,33 +106,33 @@ type Transaction interface { // IsRuleEngineOff will return true if RuleEngine is set to Off IsRuleEngineOff() bool - // RequestBodyAccessible will return true if RequestBody access has been enabled by RequestBodyAccess + // IsRequestBodyAccessible will return true if RequestBody access has been enabled by RequestBodyAccess // // This can be used to perform checks just before calling request body related functions. // In order to avoid any risk of performing wrong early assumptions, perform early checks on this value // only if the API consumer requires them for specific server/proxy actions // (such as avoiding proxy side buffering). // Note: it returns the current status, later rules may still change it via ctl actions. - RequestBodyAccessible() bool + IsRequestBodyAccessible() bool - // ResponseBodyAccessible will return true if ResponseBody access has been enabled by ResponseBodyAccess + // IsResponseBodyAccessible will return true if ResponseBody access has been enabled by ResponseBodyAccess // // This can be used to perform checks just before calling response body related functions. // In order to avoid any risk of performing wrong early assumptions, perform early checks on this value // only if the API consumer requires them for specific server/proxy actions // (such as avoiding proxy side buffering). // Note: it returns the current status, later rules may still change it via ctl actions. - ResponseBodyAccessible() bool + IsResponseBodyAccessible() bool - // IsProcessableResponseBody returns true if the response body meets the + // IsResponseBodyProcessable returns true if the response body meets the // criteria to be processed, response headers must be set before this. // The content-type response header must be in the SecResponseBodyMimeType // This is used by webservers to choose whether to stream response buffers // directly to the client or write them to Coraza's buffer. - IsProcessableResponseBody() bool + IsResponseBodyProcessable() bool - // Interrupted will return true if the transaction was interrupted - Interrupted() bool + // IsInterrupted will return true if the transaction was interrupted + IsInterrupted() bool // Interruption returns the types.Interruption if the request was interrupted, // or nil otherwise.