@@ -146,6 +146,7 @@ ngx_http_modsecurity_process_intervention (Transaction *transaction, ngx_http_re
146146 intervention .log = NULL ;
147147 intervention .disruptive = 0 ;
148148 ngx_http_modsecurity_ctx_t * ctx = NULL ;
149+ ngx_http_modsecurity_conf_t * mcf ;
149150
150151 dd ("processing intervention" );
151152
@@ -160,12 +161,20 @@ ngx_http_modsecurity_process_intervention (Transaction *transaction, ngx_http_re
160161 return 0 ;
161162 }
162163
163- log = intervention . log ;
164- if (intervention . log == NULL ) {
165- log = "(no log message was specified)" ;
164+ mcf = ngx_http_get_module_loc_conf ( r , ngx_http_modsecurity_module ) ;
165+ if (mcf == NULL ) {
166+ return NGX_HTTP_INTERNAL_SERVER_ERROR ;
166167 }
167168
168- ngx_log_error (NGX_LOG_ERR , (ngx_log_t * )r -> connection -> log , 0 , "%s" , log );
169+ // logging to nginx error log can be disable by setting `modsecurity_error_log` to off
170+ if (mcf -> error_log ) {
171+ log = intervention .log ;
172+ if (intervention .log == NULL ) {
173+ log = "(no log message was specified)" ;
174+ }
175+
176+ ngx_log_error (NGX_LOG_ERR , (ngx_log_t * )r -> connection -> log , 0 , "%s" , log );
177+ }
169178
170179 if (intervention .log != NULL ) {
171180 free (intervention .log );
@@ -226,7 +235,7 @@ ngx_http_modsecurity_process_intervention (Transaction *transaction, ngx_http_re
226235 dd ("intervention -- calling log handler manually with code: %d" , intervention .status );
227236 ngx_http_modsecurity_log_handler (r );
228237 ctx -> logged = 1 ;
229- }
238+ }
230239
231240 if (r -> header_sent )
232241 {
@@ -465,23 +474,23 @@ static ngx_command_t ngx_http_modsecurity_commands[] = {
465474 NGX_HTTP_LOC_CONF |NGX_HTTP_SRV_CONF |NGX_HTTP_MAIN_CONF |NGX_CONF_TAKE1 ,
466475 ngx_conf_set_rules ,
467476 NGX_HTTP_LOC_CONF_OFFSET ,
468- offsetof( ngx_http_modsecurity_conf_t , enable ) ,
477+ 0 ,
469478 NULL
470479 },
471480 {
472481 ngx_string ("modsecurity_rules_file" ),
473482 NGX_HTTP_LOC_CONF |NGX_HTTP_SRV_CONF |NGX_HTTP_MAIN_CONF |NGX_CONF_TAKE1 ,
474483 ngx_conf_set_rules_file ,
475484 NGX_HTTP_LOC_CONF_OFFSET ,
476- offsetof( ngx_http_modsecurity_conf_t , enable ) ,
485+ 0 ,
477486 NULL
478487 },
479488 {
480489 ngx_string ("modsecurity_rules_remote" ),
481490 NGX_HTTP_LOC_CONF |NGX_HTTP_SRV_CONF |NGX_HTTP_MAIN_CONF |NGX_CONF_TAKE2 ,
482491 ngx_conf_set_rules_remote ,
483492 NGX_HTTP_LOC_CONF_OFFSET ,
484- offsetof( ngx_http_modsecurity_conf_t , enable ) ,
493+ 0 ,
485494 NULL
486495 },
487496 {
@@ -492,6 +501,14 @@ static ngx_command_t ngx_http_modsecurity_commands[] = {
492501 0 ,
493502 NULL
494503 },
504+ {
505+ ngx_string ("modsecurity_error_log" ),
506+ NGX_HTTP_LOC_CONF |NGX_HTTP_SRV_CONF |NGX_HTTP_MAIN_CONF |NGX_CONF_FLAG ,
507+ ngx_conf_set_flag_slot ,
508+ NGX_HTTP_LOC_CONF_OFFSET ,
509+ offsetof(ngx_http_modsecurity_conf_t , error_log ),
510+ NULL
511+ },
495512 ngx_null_command
496513};
497514
@@ -703,6 +720,7 @@ ngx_http_modsecurity_create_conf(ngx_conf_t *cf)
703720 conf -> rules_set = msc_create_rules_set ();
704721 conf -> pool = cf -> pool ;
705722 conf -> transaction_id = NGX_CONF_UNSET_PTR ;
723+ conf -> error_log = NGX_CONF_UNSET ;
706724#if defined(MODSECURITY_SANITY_CHECKS ) && (MODSECURITY_SANITY_CHECKS )
707725 conf -> sanity_checks_enabled = NGX_CONF_UNSET ;
708726#endif
@@ -742,6 +760,7 @@ ngx_http_modsecurity_merge_conf(ngx_conf_t *cf, void *parent, void *child)
742760
743761 ngx_conf_merge_value (c -> enable , p -> enable , 0 );
744762 ngx_conf_merge_ptr_value (c -> transaction_id , p -> transaction_id , NULL );
763+ ngx_conf_merge_value (c -> error_log , p -> error_log , 1 );
745764#if defined(MODSECURITY_SANITY_CHECKS ) && (MODSECURITY_SANITY_CHECKS )
746765 ngx_conf_merge_value (c -> sanity_checks_enabled , p -> sanity_checks_enabled , 0 );
747766#endif
0 commit comments