Skip to content

Commit 935e68c

Browse files
authored
Merge pull request #3192 from marcstern/v2/pr/errorlog
Use standard httpd logging format in error log
2 parents 914c1a1 + d704af6 commit 935e68c

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

.github/workflows/ci.yml

+11-1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,14 @@ jobs:
4949
run: |
5050
sudo systemctl restart apache2.service
5151
sudo cat /var/log/apache2/error.log
52-
52+
- name: Check error.log
53+
run: |
54+
# Send requests & check log format
55+
# Valid request
56+
curl -s http://127.0.01/ > /dev/null || echo $?
57+
# Invalid request
58+
curl -s http://127.0.01/%2e%2f > /dev/null || echo $?
59+
# Check log format
60+
grep -F ModSecurity < /var/log/apache2/error.log | grep -vP "^\[[^\]]+\] \[security2:[a-z]+\] \[pid [0-9]+:tid [0-9]+\] (?:\[client [0-9.:]+\] )?ModSecurity" || exit 0
61+
# grep -v succeeded => found some lines with invalid format
62+
exit 1

apache2/apache2_util.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -286,19 +286,16 @@ static void internal_log_ex(request_rec *r, directory_config *dcfg, modsec_rec *
286286

287287
#if AP_SERVER_MAJORVERSION_NUMBER > 1 && AP_SERVER_MINORVERSION_NUMBER > 2
288288
ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
289-
"[client %s] ModSecurity: %s%s [uri \"%s\"]%s", r->useragent_ip ? r->useragent_ip : r->connection->client_ip, str1,
290-
hostname, log_escape(msr->mp, r->uri), unique_id);
289+
"ModSecurity: %s%s [uri \"%s\"]%s", str1, hostname, log_escape(msr->mp, r->uri), unique_id);
291290
#else
292291
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r->server,
293-
"[client %s] ModSecurity: %s%s [uri \"%s\"]%s", msr->remote_addr ? msr->remote_addr : r->connection->remote_ip, str1,
294-
hostname, log_escape(msr->mp, r->uri), unique_id);
292+
"ModSecurity: %s%s [uri \"%s\"]%s", str1, hostname, log_escape(msr->mp, r->uri), unique_id);
295293
#endif
296294

297295
/* Add this message to the list. */
298296
if (msr != NULL) {
299297
/* Force relevency if this is an alert */
300298
msr->is_relevant++;
301-
302299
*(const char **)apr_array_push(msr->alerts) = apr_pstrdup(msr->mp, str1);
303300
}
304301
}

apache2/mod_security2.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,17 @@ static int server_limit, thread_limit;
103103
*
104104
* \param mp Pointer to memory pool
105105
*/
106-
static void version(apr_pool_t *mp) {
106+
static void version(apr_pool_t *mp, server_rec* s) {
107107
char *pcre_vrs = NULL;
108108
const char *pcre_loaded_vrs = NULL;
109109
char pcre2_loaded_vrs_buffer[80] ={0};
110110

111-
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL,
111+
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s,
112112
"ModSecurity: APR compiled version=\"%s\"; "
113113
"loaded version=\"%s\"", APR_VERSION_STRING, apr_version_string());
114114

115115
if (strstr(apr_version_string(), APR_VERSION_STRING) == NULL) {
116-
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, "ModSecurity: Loaded APR do not match with compiled!");
116+
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, "ModSecurity: Loaded APR do not match with compiled!");
117117
}
118118

119119
#ifdef WITH_PCRE2
@@ -134,21 +134,21 @@ static void version(apr_pool_t *mp) {
134134
"loaded version=\"%s\"", pcre_vrs, pcre_loaded_vrs);
135135

136136
if (strstr(pcre_loaded_vrs,pcre_vrs) == NULL) {
137-
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, "ModSecurity: Loaded PCRE do not match with compiled!");
137+
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, "ModSecurity: Loaded PCRE do not match with compiled!");
138138
}
139139

140140
/* Lua version function was removed in current 5.1. Need to check in future versions if it's back */
141141
#if defined(WITH_LUA)
142-
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL,
142+
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s,
143143
"ModSecurity: LUA compiled version=\"%s\"", LUA_VERSION);
144144
#endif /* WITH_LUA */
145145

146146
#ifdef WITH_YAJL
147-
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL,
147+
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s,
148148
"ModSecurity: YAJL compiled version=\"%d.%d.%d\"", YAJL_MAJOR, YAJL_MINOR, YAJL_MICRO);
149149
#endif /* WITH_YAJL */
150150

151-
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL,
151+
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s,
152152
"ModSecurity: LIBXML compiled version=\"%s\"", LIBXML_DOTTED_VERSION);
153153
}
154154

@@ -778,7 +778,7 @@ static int hook_post_config(apr_pool_t *mp, apr_pool_t *mp_log, apr_pool_t *mp_t
778778
ap_log_error(APLOG_MARK, APLOG_NOTICE | APLOG_NOERRNO, 0, s,
779779
"%s configured.", MODSEC_MODULE_NAME_FULL);
780780

781-
version(mp);
781+
version(mp, s);
782782

783783
/* If we've changed the server signature make note of the original. */
784784
if (new_server_signature != NULL) {

configure.ac

+2-2
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,10 @@ fi
309309

310310
AC_ARG_ENABLE(assertions,
311311
AS_HELP_STRING([--enable-assertions],
312-
[Turn on assertions checks (undefine NDEBUG)]),
312+
[Turn on assertions checks (undefine NDEBUG, define _GLIBCXX_ASSERTIONS & _FORTIFY_SOURCE)]),
313313
[
314314
if test "${enableval}" = "yes"; then
315-
assertions='-UNDEBUG'
315+
assertions='-UNDEBUG -D_FORTIFY_SOURCE=3 -D_GLIBCXX_ASSERTIONS'
316316
else
317317
assertions='-DNDEBUG'
318318
fi

0 commit comments

Comments
 (0)