Repository: corazawaf/coraza
Pull request #518 (2022-11-28 23:17:53)

breaking: rename methods for a better description of what they do.
While these are breaking changes, I think the naming describes better what they do.

> Thank you for contributing to Coraza WAF, your effort is greatly appreciated
> Before submitting check if what you want to add to `coraza` list meets [quality standards](https://github.com/corazawaf/coraza/blob/master/CONTRIBUTING.md#quality-standards) before sending pull request. Thanks!

**Make sure that you've checked the boxes below before you submit PR:**

- [ ] My code includes positive and negative tests.
- [ ] I have an appropriate description with correct grammar.
- [ ] I have read [Contribution guidelines](https://github.com/corazawaf/coraza/blob/master/CONTRIBUTING.md#contribution-guidelines), [maintainers note](https://github.com/corazawaf/coraza/blob/master/CONTRIBUTING.md#maintainers) and [Quality standard](https://github.com/github.com/corazawaf/coraza/v3sso/coraza-waf/blob/master/CONTRIBUTING.md#quality-standards).
- [ ] My code is properly linted and passes pre-commit tests.

Thanks for your contribution :heart:

sonarcloud[bot]: SonarCloud Quality Gate failed.&nbsp; &nbsp; [![Quality Gate failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/failed-16px.png 'Quality Gate failed')](https://sonarcloud.io/dashboard?id=coraza&pullRequest=518)

[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=coraza&pullRequest=518&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=coraza&pullRequest=518&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=coraza&pullRequest=518&resolved=false&types=BUG)  
[![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=coraza&pullRequest=518&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=coraza&pullRequest=518&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=coraza&pullRequest=518&resolved=false&types=VULNERABILITY)  
[![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=coraza&pullRequest=518&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=coraza&pullRequest=518&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=coraza&pullRequest=518&resolved=false&types=SECURITY_HOTSPOT)  
[![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=coraza&pullRequest=518&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=coraza&pullRequest=518&resolved=false&types=CODE_SMELL) [82 Code Smells](https://sonarcloud.io/project/issues?id=coraza&pullRequest=518&resolved=false&types=CODE_SMELL)

[![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/0-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=coraza&pullRequest=518&metric=new_coverage&view=list) [0.0% Coverage](https://sonarcloud.io/component_measures?id=coraza&pullRequest=518&metric=new_coverage&view=list)  
[![0.1%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.1%')](https://sonarcloud.io/component_measures?id=coraza&pullRequest=518&metric=new_duplicated_lines_density&view=list) [0.1% Duplication](https://sonarcloud.io/component_measures?id=coraza&pullRequest=518&metric=new_duplicated_lines_density&view=list)


sonarcloud[bot]: SonarCloud Quality Gate failed.&nbsp; &nbsp; [![Quality Gate failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/failed-16px.png 'Quality Gate failed')](https://sonarcloud.io/dashboard?id=coraza&pullRequest=518)

[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=coraza&pullRequest=518&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=coraza&pullRequest=518&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=coraza&pullRequest=518&resolved=false&types=BUG)  
[![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=coraza&pullRequest=518&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=coraza&pullRequest=518&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=coraza&pullRequest=518&resolved=false&types=VULNERABILITY)  
[![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=coraza&pullRequest=518&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=coraza&pullRequest=518&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=coraza&pullRequest=518&resolved=false&types=SECURITY_HOTSPOT)  
[![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=coraza&pullRequest=518&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=coraza&pullRequest=518&resolved=false&types=CODE_SMELL) [82 Code Smells](https://sonarcloud.io/project/issues?id=coraza&pullRequest=518&resolved=false&types=CODE_SMELL)

[![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/0-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=coraza&pullRequest=518&metric=new_coverage&view=list) [0.0% Coverage](https://sonarcloud.io/component_measures?id=coraza&pullRequest=518&metric=new_coverage&view=list)  
[![0.1%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.1%')](https://sonarcloud.io/component_measures?id=coraza&pullRequest=518&metric=new_duplicated_lines_density&view=list) [0.1% Duplication](https://sonarcloud.io/component_measures?id=coraza&pullRequest=518&metric=new_duplicated_lines_density&view=list)



Patch:
diff --git a/http/interceptor.go b/http/interceptor.go
index 9cbf3d6..936e686 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 9071841..6ad5639 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 9bc36f4..a49d148 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/types/transaction.go b/types/transaction.go
index f247ed2..0dfd3c0 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.


Test patch:
diff --git a/internal/seclang/rules_test.go b/internal/seclang/rules_test.go
index c59ea2e..b4094a2 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)
 		}