Skip to content

Commit e94d85e

Browse files
authored
Merge pull request microsoft#3 from Microsoft/v2/dev/logAddHostname
Add request header hostname to log
2 parents 195d326 + 34bda19 commit e94d85e

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

apache2/apache2_util.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ static void internal_log_ex(request_rec *r, directory_config *dcfg, modsec_rec *
254254
if (level <= 3) {
255255
char *unique_id = (char *)get_env_var(r, "UNIQUE_ID");
256256
char *hostname = (char *)msr->hostname;
257+
char *requestheaderhostname = (char *)r->hostname;
257258

258259
if (unique_id != NULL) {
259260
unique_id = apr_psprintf(msr->mp, " [unique_id \"%s\"]",
@@ -267,14 +268,20 @@ static void internal_log_ex(request_rec *r, directory_config *dcfg, modsec_rec *
267268
}
268269
else hostname = "";
269270

271+
if (requestheaderhostname != NULL) {
272+
requestheaderhostname = apr_psprintf(msr->mp, " [requestheaderhostname \"%s\"]",
273+
log_escape(msr->mp, requestheaderhostname));
274+
}
275+
else requestheaderhostname = "";
276+
270277
#if AP_SERVER_MAJORVERSION_NUMBER > 1 && AP_SERVER_MINORVERSION_NUMBER > 2
271278
ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
272-
"[client %s] ModSecurity: %s%s [uri \"%s\"]%s", r->useragent_ip ? r->useragent_ip : r->connection->client_ip, str1,
273-
hostname, log_escape(msr->mp, r->uri), unique_id);
279+
"[client %s] ModSecurity: %s%s [uri \"%s\"]%s%s", r->useragent_ip ? r->useragent_ip : r->connection->client_ip, str1,
280+
hostname, log_escape(msr->mp, r->uri), unique_id, requestheaderhostname);
274281
#else
275282
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r->server,
276-
"[client %s] ModSecurity: %s%s [uri \"%s\"]%s", msr->remote_addr ? msr->remote_addr : r->connection->remote_ip, str1,
277-
hostname, log_escape(msr->mp, r->uri), unique_id);
283+
"[client %s] ModSecurity: %s%s [uri \"%s\"]%s%s", msr->remote_addr ? msr->remote_addr : r->connection->remote_ip, str1,
284+
hostname, log_escape(msr->mp, r->uri), unique_id, requestheaderhostname);
278285
#endif
279286

280287
/* Add this message to the list. */

0 commit comments

Comments
 (0)