Skip to content
New issue

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

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

Already on GitHub? # to your account

inspectFile: False-positive match fixed #1311

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vimusov
Copy link

@vimusov vimusov commented Feb 21, 2025

According to modsec docs, the operator should check script output as well as its exit code. Here is the implementation. But Coraza is missing that and ignores script output completely. I prepared a patch, please review.

p.s.: Unfortunately I don't have windows platform, so if somebody can help me to implement unit test for it, I would very appretiate that.

The operator checks script exit code only and ignores the output.
As the result, false-positive match occurs.
@vimusov vimusov requested a review from a team as a code owner February 21, 2025 06:19
Copy link

codecov bot commented Feb 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.77%. Comparing base (77fb22c) to head (cded15c).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1311   +/-   ##
=======================================
  Coverage   81.77%   81.77%           
=======================================
  Files         170      170           
  Lines        9777     9777           
=======================================
  Hits         7995     7995           
  Misses       1533     1533           
  Partials      249      249           
Flag Coverage Δ
coraza.rule.case_sensitive_args_keys 81.73% <100.00%> (ø)
coraza.rule.multiphase_valuation 81.77% <100.00%> (ø)
coraza.rule.no_regex_multiline 81.71% <100.00%> (ø)
default 81.77% <100.00%> (ø)
examples+ 16.54% <0.00%> (ø)
examples+coraza.rule.case_sensitive_args_keys 81.73% <100.00%> (ø)
examples+coraza.rule.multiphase_valuation 81.60% <100.00%> (ø)
examples+coraza.rule.no_regex_multiline 81.63% <100.00%> (ø)
examples+memoize_builders 81.73% <100.00%> (ø)
examples+no_fs_access 81.05% <100.00%> (ø)
ftw 81.77% <100.00%> (ø)
memoize_builders 81.86% <100.00%> (ø)
no_fs_access 81.22% <100.00%> (ø)
tinygo 81.74% <100.00%> (ø)

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.

if ctx.Err() == context.DeadlineExceeded || err != nil {
return false
}
return true
return len(output) > 0 && output[0] != '1'
Copy link
Member

Choose a reason for hiding this comment

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

What is this condition about output[0] != '1'?

Copy link
Author

Choose a reason for hiding this comment

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

It checks the first byte of the script output. Value 1 means that rule not matches. Any other value (e.g. 0) means that rule matches. I was unable to find any standard or specification of that "protocol". But there's an example script in modsec 2.x docs that prints 0 or 1 in depending on clamd scan result. Also, both modsec 2.x and 3.x implementations uses the first byte of script output, here are links: version 2.9.8 and version 3.0.13. Thus, my patch is an exact 1:1 port of C/C++ modsec 2/3 logic.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants