Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: BodyLimit related documented default values, default RequestBodyLimitAction, adds some tests #895

Merged
merged 12 commits into from
Feb 6, 2024

Conversation

M4tteoP
Copy link
Member

@M4tteoP M4tteoP commented Oct 29, 2023

This PR:

  • Fixes SecRequestBodyLimit, SecRequestBodyInMemoryLimit, and SecResponseBodyLimit documented default values.
  • Fixes the default RequestBodyLimitAction
  • Explicits that SecRequestBodyNoFilesLimit is not implemented

Even if relying on the provided coraza.conf-recommended file makes all these default values not used, we should still keep consistency between the actual code and its documentation

@M4tteoP M4tteoP changed the title Fix bodylimits doc Fix BodyLimit related documentd default values, default RequestBodyLimitAction, adds some tests Oct 29, 2023
@M4tteoP M4tteoP changed the title Fix BodyLimit related documentd default values, default RequestBodyLimitAction, adds some tests fix: BodyLimit related documentd default values, default RequestBodyLimitAction, adds some tests Oct 29, 2023
@codecov
Copy link

codecov bot commented Oct 29, 2023

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (4ff1f76) 82.72% compared to head (64cdef0) 83.22%.
Report is 5 commits behind head on main.

Files Patch % Lines
internal/corazawaf/rule.go 84.84% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #895      +/-   ##
==========================================
+ Coverage   82.72%   83.22%   +0.50%     
==========================================
  Files         162      162              
  Lines        9080     7552    -1528     
==========================================
- Hits         7511     6285    -1226     
+ Misses       1319     1019     -300     
+ Partials      250      248       -2     
Flag Coverage Δ
default 83.22% <87.80%> (+5.38%) ⬆️
examples 83.22% <87.80%> (+56.79%) ⬆️
ftw 83.22% <87.80%> (+35.85%) ⬆️
ftw-multiphase 83.22% <87.80%> (+33.67%) ⬆️
tinygo 83.22% <87.80%> (+7.81%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -276,6 +277,7 @@ func NewWAF() *WAF {
RuleEngine: types.RuleEngineOn,
RequestBodyAccess: false,
RequestBodyLimit: _1gb,
RequestBodyLimitAction: types.BodyLimitActionReject,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per https://coraza.io/docs/seclang/directives/#secrequestbodylimitaction, the default value for the request body limit action is Reject. We can't rely on the zero value of the BodyLimit action because we want to have two different default values for RequestBodyLimitAction (reject) and ResponseBodyLimitAction (processPartial). The first one has been explicited here

@@ -229,7 +229,7 @@ func directiveSecResponseBodyAccess(options *DirectiveOptions) error {
}

// Description: Configures the maximum request body size Coraza will accept for buffering.
// Default: 134217728 (131072 KB)
// Default: 1073741824 (1024 MiB)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See

RequestBodyLimit: _1gb,

Copy link
Member

@jcchavezs jcchavezs Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some confusion here. _1gb is the hard limit and not the default one (1gb for the default one is cray IMO). Maybe it is better to set to -1 and fail if not set? cc @anuraaga

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since 6482ab1, seems like it is effectively not just the hard limit, but also the default one. Here I wanted to at least align the doc with the implementation.
I agree that it is not the best default value: I'm okay with both setting the default value to the one that users are used from ModSec, or making it a requirement.

This is basically the evolution of #612 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it is the default one without applying the recommended conf. I think making body limit so huge could be problematic so maybe we align the documented default values with the ones in code? cc @anuraaga @jptosso

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree about aligning code to doc

@@ -448,7 +448,7 @@ func directiveSecRequestBodyLimitAction(options *DirectiveOptions) error {
}

// Description: Configures the maximum request body size that Coraza will store in memory.
// Default: 131072 (128 KB)
// Default: defaults to RequestBodyLimit
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See

// if no requestBodyInMemoryLimit has been set we default to the
var requestBodyInMemoryLimit int64 = w.RequestBodyLimit
if w.requestBodyInMemoryLimit != nil {
requestBodyInMemoryLimit = int64(*w.requestBodyInMemoryLimit)
}

@M4tteoP M4tteoP force-pushed the fix_bodylimits_doc branch from eee0aa9 to 6be7862 Compare October 29, 2023 14:37
@M4tteoP M4tteoP changed the title fix: BodyLimit related documentd default values, default RequestBodyLimitAction, adds some tests fix: BodyLimit related documented default values, default RequestBodyLimitAction, adds some tests Oct 29, 2023
@M4tteoP M4tteoP marked this pull request as ready for review October 29, 2023 14:39
@M4tteoP M4tteoP requested a review from a team as a code owner October 29, 2023 14:39
@@ -45,7 +45,7 @@ SecRequestBodyLimit 13107200

SecRequestBodyInMemoryLimit 131072

SecRequestBodyNoFilesLimit 131072
# SecRequestBodyNoFilesLimit 131072
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Being not implemented, I think we should at least comment it out, not letting users think that it is an enforced configuration

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a comment too, # Coraza currently does not read this parameter I think

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also open an issue for this? Are we supporting it @jptosso ?

Copy link
Member Author

@M4tteoP M4tteoP Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the following comment: # SecRequestBodyNoFilesLimit is currently not supported by Coraza. As far as I can see, we actually just read the parameter, but we do not enforce any logic based on this.
Opened issue #896 about it.

@@ -45,7 +45,7 @@ SecRequestBodyLimit 13107200

SecRequestBodyInMemoryLimit 131072

SecRequestBodyNoFilesLimit 131072
# SecRequestBodyNoFilesLimit 131072
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a comment too, # Coraza currently does not read this parameter I think

@M4tteoP M4tteoP force-pushed the fix_bodylimits_doc branch from b8c0246 to 9ee9745 Compare October 30, 2023 16:52
@M4tteoP
Copy link
Member Author

M4tteoP commented Dec 13, 2023

Anyone PTAL, I think it is ready to be merged

@M4tteoP M4tteoP requested a review from a team December 13, 2023 15:28
@@ -876,6 +876,8 @@ func directiveSecUploadDir(options *DirectiveOptions) error {
return nil
}

// Not implemented yet
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this will work for autogeneration. Everything not being key:value (e.g. Description: Configures....) should go after the

// ---

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, moved as // Note: not implemented yet as the last line

@jcchavezs jcchavezs merged commit 3c15624 into corazawaf:main Feb 6, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants