Skip to content

Fixed mandatory check of rule ID. #1325

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

brijeshjvalera
Copy link

@brijeshjvalera brijeshjvalera commented Mar 11, 2025

Fixed strict check: The id action is required for all SecRule/SecAction.

Make sure that you've checked the boxes below before you submit PR:

Thanks for your contribution ❤️

@brijeshjvalera brijeshjvalera requested a review from a team as a code owner March 11, 2025 17:26
Copy link

codecov bot commented Mar 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.98%. Comparing base (4722c9a) to head (20a10aa).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1325      +/-   ##
==========================================
+ Coverage   81.94%   81.98%   +0.03%     
==========================================
  Files         170      170              
  Lines        9777     9781       +4     
==========================================
+ Hits         8012     8019       +7     
+ Misses       1518     1516       -2     
+ Partials      247      246       -1     
Flag Coverage Δ
coraza.rule.case_sensitive_args_keys 81.94% <100.00%> (+0.03%) ⬆️
coraza.rule.multiphase_valuation 81.98% <100.00%> (+0.03%) ⬆️
coraza.rule.no_regex_multiline 81.92% <100.00%> (+0.03%) ⬆️
default 81.98% <100.00%> (+0.03%) ⬆️
examples+ 16.55% <14.28%> (+<0.01%) ⬆️
examples+coraza.rule.case_sensitive_args_keys 81.94% <100.00%> (+0.03%) ⬆️
examples+coraza.rule.multiphase_valuation 81.82% <100.00%> (+0.03%) ⬆️
examples+coraza.rule.no_regex_multiline 81.84% <100.00%> (+0.03%) ⬆️
examples+memoize_builders 81.94% <100.00%> (+0.03%) ⬆️
examples+no_fs_access 81.26% <100.00%> (+0.03%) ⬆️
ftw 81.98% <100.00%> (+0.03%) ⬆️
memoize_builders 82.07% <100.00%> (+0.03%) ⬆️
no_fs_access 81.43% <100.00%> (+0.03%) ⬆️
tinygo 81.95% <100.00%> (+0.03%) ⬆️

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.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

if err != nil {
t.Error(err)
}
err = p.FromString(`SecRule &REQUEST_COOKIES_NAMES:'/.*/'|ARGS:/a|b/ "id:4"`)
err = p.FromString(`SecRule &REQUEST_COOKIES_NAMES:'/.*/'|ARGS:/a|b/ "" "id:4"`)
Copy link
Member

Choose a reason for hiding this comment

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

curious why this empty string is needed.

Copy link
Author

Choose a reason for hiding this comment

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

p.FromString() will fail as it has to follow the syntax: SecRule VARIABLES OPERATOR [ACTIONS]. Without empty string(""), "id:4" is treated as operator (will be treated as @rx id:3, @rx as default operator).
Testcase will fail with this as it will not find any ID action specified in the rule.

Copy link

Choose a reason for hiding this comment

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

A side note: we already started a discussion about this implicit @rx operator's role, see ModSecurity issue #3081. Feel free to leave a comment.

M4tteoP
M4tteoP previously approved these changes Mar 13, 2025
Copy link
Member

@M4tteoP M4tteoP left a comment

Choose a reason for hiding this comment

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

Thanks for this!

Addressed review comments.

Co-authored-by: Matteo Pace <[email protected]>
@M4tteoP
Copy link
Member

M4tteoP commented Mar 14, 2025

Let question from my side: here we are enforcing a check that, as per the documentation, has always been expected to work this way. However, it would be a breaking change for those not compliant with the documentation. Should we add a build flag to enable this check, or can we mention it in the release notes and require users to fix non-compliant rules when upgrading the minor version? @corazawaf/maintainers

@jcchavezs
Copy link
Member

I would go for the build tag otherwise it can be a breaking change.

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.

5 participants