Skip to content

Commit 4f26b48

Browse files
committed
Avoid extra processing of subsequent interventions if one was already triggered
1 parent e028ca4 commit 4f26b48

5 files changed

+16
-0
lines changed

src/ngx_http_modsecurity_body_filter.c

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ ngx_http_modsecurity_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
5656
return ngx_http_next_body_filter(r, in);
5757
}
5858

59+
if (ctx->intervention_triggered) {
60+
return ngx_http_next_body_filter(r, in);
61+
}
62+
5963
#if defined(MODSECURITY_SANITY_CHECKS) && (MODSECURITY_SANITY_CHECKS)
6064
mcf = ngx_http_get_module_loc_conf(r, ngx_http_modsecurity_module);
6165
if (mcf != NULL && mcf->sanity_checks_enabled != NGX_CONF_UNSET)

src/ngx_http_modsecurity_common.h

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ typedef struct {
9797
unsigned waiting_more_body:1;
9898
unsigned body_requested:1;
9999
unsigned processed:1;
100+
unsigned intervention_triggered:1;
100101
} ngx_http_modsecurity_ctx_t;
101102

102103

src/ngx_http_modsecurity_header_filter.c

+4
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,10 @@ ngx_http_modsecurity_header_filter(ngx_http_request_t *r)
430430
return ngx_http_next_header_filter(r);
431431
}
432432

433+
if (ctx->intervention_triggered) {
434+
return ngx_http_next_header_filter(r);
435+
}
436+
433437
/* XXX: can it happen ? already processed i mean */
434438
/* XXX: check behaviour on 'ModSecurity off' */
435439

src/ngx_http_modsecurity_pre_access.c

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ ngx_http_modsecurity_pre_access_handler(ngx_http_request_t *r)
7878
return NGX_HTTP_INTERNAL_SERVER_ERROR;
7979
}
8080

81+
if (ctx->intervention_triggered) {
82+
return NGX_DECLINED;
83+
}
84+
8185
if (ctx->waiting_more_body == 1)
8286
{
8387
dd("waiting for more data before proceed. / count: %d",

src/ngx_http_modsecurity_rewrite.c

+3
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ ngx_http_modsecurity_rewrite_handler(ngx_http_request_t *r)
117117
dd("Processing intervention with the connection information filled in");
118118
ret = ngx_http_modsecurity_process_intervention(ctx->modsec_transaction, r);
119119
if (ret > 0) {
120+
ctx->intervention_triggered = 1;
120121
return ret;
121122
}
122123

@@ -157,6 +158,7 @@ ngx_http_modsecurity_rewrite_handler(ngx_http_request_t *r)
157158
dd("Processing intervention with the transaction information filled in (uri, method and version)");
158159
ret = ngx_http_modsecurity_process_intervention(ctx->modsec_transaction, r);
159160
if (ret > 0) {
161+
ctx->intervention_triggered = 1;
160162
return ret;
161163
}
162164

@@ -208,6 +210,7 @@ ngx_http_modsecurity_rewrite_handler(ngx_http_request_t *r)
208210
return NGX_DECLINED;
209211
}
210212
if (ret > 0) {
213+
ctx->intervention_triggered = 1;
211214
return ret;
212215
}
213216
}

0 commit comments

Comments
 (0)