Skip to content

Commit 472e437

Browse files
committed
Use the context to decide whether ModSecurity is enabled or not
Currently, the connector decides whether ModSecurity is enabled or not based on the configuration directive in the request's location conf. In case of an internal redirect and if ModSecurity is not enabled in the internal redirect's location conf, the log handler will not run and the transaction of the original request will not be logged. This commit extends the current behavior of the header and body filters, which assume that a null context means that ModSecurity is disabled, to the pre access and log handlers. As a result, the connector will always decide based on the original request whether ModSecurity is enabled or not.
1 parent 87a2af8 commit 472e437

4 files changed

+6
-20
lines changed

Diff for: src/ngx_http_modsecurity_body_filter.c

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ ngx_http_modsecurity_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
5353
dd("body filter, recovering ctx: %p", ctx);
5454

5555
if (ctx == NULL) {
56+
dd("ModSecurity not enabled or an error occured");
5657
return ngx_http_next_body_filter(r, in);
5758
}
5859

Diff for: src/ngx_http_modsecurity_header_filter.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ ngx_http_modsecurity_header_filter(ngx_http_request_t *r)
426426

427427
if (ctx == NULL)
428428
{
429-
dd("something really bad happened or ModSecurity is disabled. going to the next filter.");
429+
dd("ModSecurity not enabled or an error occured");
430430
return ngx_http_next_header_filter(r);
431431
}
432432

Diff for: src/ngx_http_modsecurity_log.c

+2-10
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,9 @@ ngx_http_modsecurity_log_handler(ngx_http_request_t *r)
3939
{
4040
ngx_pool_t *old_pool;
4141
ngx_http_modsecurity_ctx_t *ctx;
42-
ngx_http_modsecurity_conf_t *mcf;
4342

4443
dd("catching a new _log_ phase handler");
4544

46-
mcf = ngx_http_get_module_loc_conf(r, ngx_http_modsecurity_module);
47-
if (mcf == NULL || mcf->enable != 1)
48-
{
49-
dd("ModSecurity not enabled... returning");
50-
return NGX_OK;
51-
}
52-
5345
/*
5446
if (r->method != NGX_HTTP_GET &&
5547
r->method != NGX_HTTP_POST && r->method != NGX_HTTP_HEAD) {
@@ -63,8 +55,8 @@ ngx_http_modsecurity_log_handler(ngx_http_request_t *r)
6355
dd("recovering ctx: %p", ctx);
6456

6557
if (ctx == NULL) {
66-
dd("something really bad happened here. returning NGX_ERROR");
67-
return NGX_ERROR;
58+
dd("ModSecurity not enabled or an error occured");
59+
return NGX_OK;
6860
}
6961

7062
dd("calling msc_process_logging for %p", ctx);

Diff for: src/ngx_http_modsecurity_pre_access.c

+2-9
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,9 @@ ngx_http_modsecurity_pre_access_handler(ngx_http_request_t *r)
4646
#if 1
4747
ngx_pool_t *old_pool;
4848
ngx_http_modsecurity_ctx_t *ctx;
49-
ngx_http_modsecurity_conf_t *mcf;
5049

5150
dd("catching a new _preaccess_ phase handler");
5251

53-
mcf = ngx_http_get_module_loc_conf(r, ngx_http_modsecurity_module);
54-
if (mcf == NULL || mcf->enable != 1)
55-
{
56-
dd("ModSecurity not enabled... returning");
57-
return NGX_DECLINED;
58-
}
5952
/*
6053
* FIXME:
6154
* In order to perform some tests, let's accept everything.
@@ -74,8 +67,8 @@ ngx_http_modsecurity_pre_access_handler(ngx_http_request_t *r)
7467

7568
if (ctx == NULL)
7669
{
77-
dd("ctx is null; Nothing we can do, returning an error.");
78-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
70+
dd("ModSecurity not enabled or an error occured");
71+
return NGX_DECLINED;
7972
}
8073

8174
if (ctx->request_body_processed) {

0 commit comments

Comments
 (0)