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

audit: H should populate also with error logs. #1310

Merged
merged 7 commits into from
Mar 21, 2025

Conversation

M4tteoP
Copy link
Member

@M4tteoP M4tteoP commented Feb 19, 2025

Part of #1305.
Address point 1 of #1305 (comment)

Copy link

codecov bot commented Feb 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.99%. Comparing base (cb80190) to head (b5f4154).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1310      +/-   ##
==========================================
+ Coverage   81.94%   81.99%   +0.04%     
==========================================
  Files         170      170              
  Lines        9777     9803      +26     
==========================================
+ Hits         8012     8038      +26     
  Misses       1518     1518              
  Partials      247      247              
Flag Coverage Δ
coraza.rule.case_sensitive_args_keys 81.95% <100.00%> (+0.04%) ⬆️
coraza.rule.multiphase_valuation 81.99% <100.00%> (+0.04%) ⬆️
coraza.rule.no_regex_multiline 81.93% <100.00%> (+0.04%) ⬆️
default 81.99% <100.00%> (+0.04%) ⬆️
examples+ 16.50% <0.00%> (-0.05%) ⬇️
examples+coraza.rule.case_sensitive_args_keys 81.95% <100.00%> (+0.04%) ⬆️
examples+coraza.rule.multiphase_valuation 81.83% <100.00%> (+0.04%) ⬆️
examples+coraza.rule.no_regex_multiline 81.85% <100.00%> (+0.04%) ⬆️
examples+memoize_builders 81.95% <100.00%> (+0.04%) ⬆️
examples+no_fs_access 81.28% <100.00%> (+0.04%) ⬆️
ftw 81.99% <100.00%> (+0.04%) ⬆️
memoize_builders 82.08% <100.00%> (+0.04%) ⬆️
no_fs_access 81.44% <100.00%> (+0.04%) ⬆️
tinygo 81.96% <100.00%> (+0.04%) ⬆️

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.

@M4tteoP M4tteoP force-pushed the audit_populate_H_error_logs branch from 1098a44 to df5b689 Compare March 2, 2025 22:14
@M4tteoP M4tteoP marked this pull request as ready for review March 2, 2025 22:21
@M4tteoP M4tteoP requested a review from a team as a code owner March 2, 2025 22:21
@M4tteoP M4tteoP force-pushed the audit_populate_H_error_logs branch 2 times, most recently from 2169a67 to 560063e Compare March 6, 2025 23:12
@@ -47,4 +47,6 @@ type MatchedRule interface {
AuditLog() string

ErrorLog() string

// TODO(4.x): Add Log()
Copy link
Member

Choose a reason for hiding this comment

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

Do you mind elaborating why?

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 remember that with #848 we agreed that Log() was indeed helpful to be exported, but then to avoid breaking the Coraza v3.* API adding a Log() method to the MatchedRule interface we provided the workaround via the type assertion. So I guess that the proper outcome is to have it properly exported.
See also

// Log action is required to log a matched rule on both error log and audit log
// An assertion has to be done to check if the MatchedRule implements the Log() function before calling Log()
// It is performed to avoid breaking the Coraza v3.* API adding a Log() method to the MatchedRule interface
mrWithlog, ok := mr.(*corazarules.MatchedRule)
if ok && mrWithlog.Log() {

for _, alEntry := range al.Messages() {
alWithErrMsg, ok := alEntry.(auditLogWithErrMesg)
if ok && alWithErrMsg.ErrorMessage() != "" {
res.WriteByte('\n')
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
res.WriteByte('\n')
fmt.Fprintln(res, "")

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 can't use it as is with a string builder (complains of missing io.Writer). We are using in several places res.WriteByte('\n'), is it a performance or readability suggestion?

Copy link
Member

Choose a reason for hiding this comment

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

it is because the method is in the pointer not in the value. The main use here is to make this working on windows but I see this has been used before so we can keep it.

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 see, thanks!

@M4tteoP M4tteoP force-pushed the audit_populate_H_error_logs branch from 560063e to 42601f5 Compare March 14, 2025 23:55
@M4tteoP
Copy link
Member Author

M4tteoP commented Mar 14, 2025

Fixed go.sum conflicts

@M4tteoP M4tteoP force-pushed the audit_populate_H_error_logs branch from 42601f5 to 07c6a2d Compare March 17, 2025 21:01
@M4tteoP M4tteoP merged commit 57eb446 into main Mar 21, 2025
72 checks passed
@M4tteoP M4tteoP deleted the audit_populate_H_error_logs branch March 21, 2025 15:41
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