Skip to content

Commit 1494b25

Browse files
committed
added disable error log support
modified old PR owasp-modsecurity#327 Signed-off-by: Fatih USTA <[email protected]>
1 parent fd28e6a commit 1494b25

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/ngx_http_modsecurity_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ typedef struct {
118118
void *rules_set;
119119

120120
ngx_flag_t enable;
121+
ngx_flag_t disable_error_log;
121122
#if defined(MODSECURITY_SANITY_CHECKS) && (MODSECURITY_SANITY_CHECKS)
122123
ngx_flag_t sanity_checks_enabled;
123124
#endif

src/ngx_http_modsecurity_module.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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,19 @@ 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_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+
}
169177

170178
if (intervention.log != NULL) {
171179
free(intervention.log);
@@ -513,6 +521,14 @@ static ngx_command_t ngx_http_modsecurity_commands[] = {
513521
0,
514522
NULL
515523
},
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+
},
516532
ngx_null_command
517533
};
518534

@@ -724,6 +740,7 @@ ngx_http_modsecurity_create_conf(ngx_conf_t *cf)
724740
conf->rules_set = msc_create_rules_set();
725741
conf->pool = cf->pool;
726742
conf->transaction_id = NGX_CONF_UNSET_PTR;
743+
conf->disable_error_log = NGX_CONF_UNSET;
727744
#if defined(MODSECURITY_SANITY_CHECKS) && (MODSECURITY_SANITY_CHECKS)
728745
conf->sanity_checks_enabled = NGX_CONF_UNSET;
729746
#endif
@@ -763,6 +780,7 @@ ngx_http_modsecurity_merge_conf(ngx_conf_t *cf, void *parent, void *child)
763780

764781
ngx_conf_merge_value(c->enable, p->enable, 0);
765782
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);
766784
#if defined(MODSECURITY_SANITY_CHECKS) && (MODSECURITY_SANITY_CHECKS)
767785
ngx_conf_merge_value(c->sanity_checks_enabled, p->sanity_checks_enabled, 0);
768786
#endif

0 commit comments

Comments
 (0)