Skip to content

Fix error logging for standalone module #3374

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 1 commit into
base: v2/master
Choose a base branch
from

Conversation

RedXanadu
Copy link

what

This PR:

  • Restores the original format string for error logging for ModSecurity when compiled as a standalone module.
  • The format string has the explicit [client %s] back again: this is required for standalone modules as Apache is not present to implicitly log the client source IP address.
  • The fix is achieved by adding conditional compilation directives so that for standalone mode the old error logging format strings are used.

why

It is essential for the client source IP address to be written to the error log. This is required for resolving false positives, monitoring, detecting attacks, and the majority of day to day WAF operations.

This PR fixes the bug introduced in an attempt to tidy error logging for Apache in PR #3192.

references

closes #3373

Restores the original format string for error logging for ModSecurity
when compiled as a standalone module. Specifically, the format string
has "[client %s]" back again: this is required for standalone modules as
Apache is not present to implicitly log the client source IP address.
Copy link

sonarqubecloud bot commented May 9, 2025

@RedXanadu
Copy link
Author

I have tested this on a standalone installation of ModSecurity v2.9.8 and can confirm that it restores client IP address logging as intended.

@airween
Copy link
Member

airween commented May 9, 2025

A reminder to me (or to us 😄) - we should add more tests, eg. which will check standalone build (and test it...?) too.

hostname, log_escape(msr->mp, r->uri), unique_id);
#else
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r->server,
"[client %s] ModSecurity: %s%s [uri \"%s\"]%s", msr->remote_addr ? msr->remote_addr : r->connection->remote_ip, str1,
Copy link
Member

Choose a reason for hiding this comment

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

Just for the better visibility, could you use here the same indent (and below in line 306 as in line 301/302?

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