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

New option that can disable modsecurity logging into nginx error log #327

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

JakubOnderka
Copy link

@JakubOnderka JakubOnderka commented Jul 1, 2024

Modsecurity module for nginx by default log the whole message in case request is blocked into nginx error log. But the same information is also logged into modsecurity audit logs, so logs can grow pretty fast in case of DDoS or scanning attacks.

This patch adds new option modsecurity_error_log that accepts on or off option. on is default that logs the whole message to error log, but it can be turned off.

It also adds new variable $modsecurity_status that contains status code from modsecurity.

@JakubOnderka JakubOnderka marked this pull request as ready for review July 2, 2024 10:58
@JakubOnderka JakubOnderka changed the title New option modsecurity_error_log that can disable modsecurity loggi… New option that can disable modsecurity logging into nginx error log Jul 2, 2024
@JakubOnderka JakubOnderka force-pushed the modsecurity_error_log branch 4 times, most recently from 2bb7357 to dcabb04 Compare July 2, 2024 15:00
This variable can be used for example in access logs to distinguish which requests was blocked by modsecurity
@JakubOnderka JakubOnderka force-pushed the modsecurity_error_log branch from dcabb04 to d5b5ebf Compare July 2, 2024 15:12
@airween
Copy link
Member

airween commented Jul 2, 2024

Hi @JakubOnderka,

thanks for this PR!

I'm sure this patch can be useful for many users, but please consider the following:

log the whole message in case request is blocked into nginx error log. But the same information is also logged into modsecurity audit logs

this depends on some circumstances. Eg. by default audit log contains the transaction related information only if the status code is 4XX or 5XX except 404 (see SecAuditLogRelevantStatus).

If someone uses Core Rule Set in anomaly scoring mode, and the transaction's score value does not reach the threshold, then those information will be lost (I mean the triggered rules).

Moreover consider if someone uses some IPS/IDS (eg. fail2ban) which uses only the error.log (as I know there is no any plugin for fail2ban which can use audit.log) - then this configuration could be unusable.

I support any new feature, but we must notice users what do they do.

so logs can grow pretty fast in case of DDoS or scanning attacks.

If the log level is lower than info in Nginx's configuration (eg. no level), then the result is almost the same (like this PR's result).

This patch adds new option modsecurity_error_log that accepts on or off option. on is default that logs the whole message to error log, but it can be turned off.

A side note, but hope others will be check this PR too and write their opinions: modsecurity_error_log refers to me that where is the log, I mean the path. May be some more informative name would be better - eg. modsecurity_use_error_log, or similar.

It also adds new variable $modsecurity_status that contains status code from modsecurity.

It would be nice to see a real example of its use. While you want to add a new configuration keyword and a new variable, please add their documentation into README.md, below the Usage section (you can do that within this PR - not a separated one). If you make the documentation for modsecurity_error_log (or the other name - we will see it), then please add the side effects too what I explained above.

And thanks again!

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.

2 participants