From 652b942cfb709918cb90b4bf627aadc0d8380820 Mon Sep 17 00:00:00 2001 From: Xanadu Date: Thu, 8 May 2025 23:17:45 +0100 Subject: [PATCH 1/2] Add extra conditional compilation for err logging 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. --- apache2/apache2_util.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/apache2/apache2_util.c b/apache2/apache2_util.c index f42436790f..f231147b74 100644 --- a/apache2/apache2_util.c +++ b/apache2/apache2_util.c @@ -284,12 +284,27 @@ static void internal_log_ex(request_rec *r, directory_config *dcfg, modsec_rec * } else hostname = ""; -#if AP_SERVER_MAJORVERSION_NUMBER > 1 && AP_SERVER_MINORVERSION_NUMBER > 2 +/* Non-standalone modules use amended format string for logging */ +#if !(defined(VERSION_STANDALONE)) + #if AP_SERVER_MAJORVERSION_NUMBER > 1 && AP_SERVER_MINORVERSION_NUMBER > 2 ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r, "ModSecurity: %s%s [uri \"%s\"]%s", str1, hostname, log_escape(msr->mp, r->uri), unique_id); -#else + #else ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r->server, "ModSecurity: %s%s [uri \"%s\"]%s", str1, hostname, log_escape(msr->mp, r->uri), unique_id); + #endif +/* Standalone module must use original format string for logging with explicit + * "[client %s]" to log client IP address (no Apache to implicitly add this) */ +#else + #if AP_SERVER_MAJORVERSION_NUMBER > 1 && AP_SERVER_MINORVERSION_NUMBER > 2 + ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r, + "[client %s] ModSecurity: %s%s [uri \"%s\"]%s", r->useragent_ip ? r->useragent_ip : r->connection->client_ip, str1, + 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, + hostname, log_escape(msr->mp, r->uri), unique_id); + #endif #endif /* Add this message to the list. */ From 0c7dadc4c722cfc2d162eecf17067789bc64dd1c Mon Sep 17 00:00:00 2001 From: RedXanadu Date: Tue, 13 May 2025 16:33:15 +0100 Subject: [PATCH 2/2] Correct indentation --- apache2/apache2_util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apache2/apache2_util.c b/apache2/apache2_util.c index f231147b74..faef43f0c5 100644 --- a/apache2/apache2_util.c +++ b/apache2/apache2_util.c @@ -302,8 +302,8 @@ static void internal_log_ex(request_rec *r, directory_config *dcfg, modsec_rec * 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, - hostname, log_escape(msr->mp, r->uri), unique_id); + "[client %s] ModSecurity: %s%s [uri \"%s\"]%s", msr->remote_addr ? msr->remote_addr : r->connection->remote_ip, str1, + hostname, log_escape(msr->mp, r->uri), unique_id); #endif #endif