@@ -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,19 @@ 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_disable_error_log` to on
170
+ if (!mcf -> disable_error_log ) {
171
+ log = intervention .log ;
172
+ if (intervention .log == NULL ) {
173
+ log = "(no log message was specified)" ;
174
+ }
175
+ ngx_log_error (NGX_LOG_ERR , (ngx_log_t * )r -> connection -> log , 0 , "%s" , log );
176
+ }
169
177
170
178
if (intervention .log != NULL ) {
171
179
free (intervention .log );
@@ -513,6 +521,14 @@ static ngx_command_t ngx_http_modsecurity_commands[] = {
513
521
0 ,
514
522
NULL
515
523
},
524
+ {
525
+ ngx_string ("modsecurity_disable_error_log" ),
526
+ NGX_HTTP_LOC_CONF |NGX_HTTP_SRV_CONF |NGX_HTTP_MAIN_CONF |NGX_CONF_FLAG ,
527
+ ngx_conf_set_flag_slot ,
528
+ NGX_HTTP_LOC_CONF_OFFSET ,
529
+ offsetof(ngx_http_modsecurity_conf_t , disable_error_log ),
530
+ NULL
531
+ },
516
532
ngx_null_command
517
533
};
518
534
@@ -724,6 +740,7 @@ ngx_http_modsecurity_create_conf(ngx_conf_t *cf)
724
740
conf -> rules_set = msc_create_rules_set ();
725
741
conf -> pool = cf -> pool ;
726
742
conf -> transaction_id = NGX_CONF_UNSET_PTR ;
743
+ conf -> disable_error_log = NGX_CONF_UNSET ;
727
744
#if defined(MODSECURITY_SANITY_CHECKS ) && (MODSECURITY_SANITY_CHECKS )
728
745
conf -> sanity_checks_enabled = NGX_CONF_UNSET ;
729
746
#endif
@@ -763,6 +780,7 @@ ngx_http_modsecurity_merge_conf(ngx_conf_t *cf, void *parent, void *child)
763
780
764
781
ngx_conf_merge_value (c -> enable , p -> enable , 0 );
765
782
ngx_conf_merge_ptr_value (c -> transaction_id , p -> transaction_id , NULL );
783
+ ngx_conf_merge_value (c -> disable_error_log , p -> disable_error_log , 0 );
766
784
#if defined(MODSECURITY_SANITY_CHECKS ) && (MODSECURITY_SANITY_CHECKS )
767
785
ngx_conf_merge_value (c -> sanity_checks_enabled , p -> sanity_checks_enabled , 0 );
768
786
#endif
0 commit comments