@@ -146,6 +146,7 @@ ngx_http_modsecurity_process_intervention (Transaction *transaction, ngx_http_re
146
146
intervention .log = NULL ;
147
147
intervention .disruptive = 0 ;
148
148
ngx_http_modsecurity_ctx_t * ctx = NULL ;
149
+ ngx_http_modsecurity_conf_t * mcf ;
149
150
150
151
dd ("processing intervention" );
151
152
@@ -160,12 +161,20 @@ ngx_http_modsecurity_process_intervention (Transaction *transaction, ngx_http_re
160
161
return 0 ;
161
162
}
162
163
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 ;
166
167
}
167
168
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
+ }
169
178
170
179
if (intervention .log != NULL ) {
171
180
free (intervention .log );
@@ -226,7 +235,7 @@ ngx_http_modsecurity_process_intervention (Transaction *transaction, ngx_http_re
226
235
dd ("intervention -- calling log handler manually with code: %d" , intervention .status );
227
236
ngx_http_modsecurity_log_handler (r );
228
237
ctx -> logged = 1 ;
229
- }
238
+ }
230
239
231
240
if (r -> header_sent )
232
241
{
@@ -465,23 +474,23 @@ static ngx_command_t ngx_http_modsecurity_commands[] = {
465
474
NGX_HTTP_LOC_CONF |NGX_HTTP_SRV_CONF |NGX_HTTP_MAIN_CONF |NGX_CONF_TAKE1 ,
466
475
ngx_conf_set_rules ,
467
476
NGX_HTTP_LOC_CONF_OFFSET ,
468
- offsetof( ngx_http_modsecurity_conf_t , enable ) ,
477
+ 0 ,
469
478
NULL
470
479
},
471
480
{
472
481
ngx_string ("modsecurity_rules_file" ),
473
482
NGX_HTTP_LOC_CONF |NGX_HTTP_SRV_CONF |NGX_HTTP_MAIN_CONF |NGX_CONF_TAKE1 ,
474
483
ngx_conf_set_rules_file ,
475
484
NGX_HTTP_LOC_CONF_OFFSET ,
476
- offsetof( ngx_http_modsecurity_conf_t , enable ) ,
485
+ 0 ,
477
486
NULL
478
487
},
479
488
{
480
489
ngx_string ("modsecurity_rules_remote" ),
481
490
NGX_HTTP_LOC_CONF |NGX_HTTP_SRV_CONF |NGX_HTTP_MAIN_CONF |NGX_CONF_TAKE2 ,
482
491
ngx_conf_set_rules_remote ,
483
492
NGX_HTTP_LOC_CONF_OFFSET ,
484
- offsetof( ngx_http_modsecurity_conf_t , enable ) ,
493
+ 0 ,
485
494
NULL
486
495
},
487
496
{
@@ -492,6 +501,14 @@ static ngx_command_t ngx_http_modsecurity_commands[] = {
492
501
0 ,
493
502
NULL
494
503
},
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
+ },
495
512
ngx_null_command
496
513
};
497
514
@@ -703,6 +720,7 @@ ngx_http_modsecurity_create_conf(ngx_conf_t *cf)
703
720
conf -> rules_set = msc_create_rules_set ();
704
721
conf -> pool = cf -> pool ;
705
722
conf -> transaction_id = NGX_CONF_UNSET_PTR ;
723
+ conf -> error_log = NGX_CONF_UNSET ;
706
724
#if defined(MODSECURITY_SANITY_CHECKS ) && (MODSECURITY_SANITY_CHECKS )
707
725
conf -> sanity_checks_enabled = NGX_CONF_UNSET ;
708
726
#endif
@@ -742,6 +760,7 @@ ngx_http_modsecurity_merge_conf(ngx_conf_t *cf, void *parent, void *child)
742
760
743
761
ngx_conf_merge_value (c -> enable , p -> enable , 0 );
744
762
ngx_conf_merge_ptr_value (c -> transaction_id , p -> transaction_id , NULL );
763
+ ngx_conf_merge_value (c -> error_log , p -> error_log , 1 );
745
764
#if defined(MODSECURITY_SANITY_CHECKS ) && (MODSECURITY_SANITY_CHECKS )
746
765
ngx_conf_merge_value (c -> sanity_checks_enabled , p -> sanity_checks_enabled , 0 );
747
766
#endif
0 commit comments