Skip to content

Commit 4f26b48

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

File tree

5 files changed

+16
-0
lines changed

5 files changed

+16
-0
lines changed

‎src/ngx_http_modsecurity_body_filter.c‎

Lines changed: 4 additions & 0 deletions
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
returnngx_http_next_body_filter(r, in);
5757
}
5858

59+
if (ctx->intervention_triggered){
60+
returnngx_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‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ typedef struct{
9797
unsignedwaiting_more_body:1;
9898
unsignedbody_requested:1;
9999
unsignedprocessed:1;
100+
unsignedintervention_triggered:1;
100101
} ngx_http_modsecurity_ctx_t;
101102

102103

‎src/ngx_http_modsecurity_header_filter.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,10 @@ ngx_http_modsecurity_header_filter(ngx_http_request_t *r)
430430
returnngx_http_next_header_filter(r);
431431
}
432432

433+
if (ctx->intervention_triggered){
434+
returnngx_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‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ ngx_http_modsecurity_pre_access_handler(ngx_http_request_t *r)
7878
returnNGX_HTTP_INTERNAL_SERVER_ERROR;
7979
}
8080

81+
if (ctx->intervention_triggered){
82+
returnNGX_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‎

Lines changed: 3 additions & 0 deletions
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
returnret;
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
returnret;
161163
}
162164

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

0 commit comments

Comments
(0)