Skip to content

Commit 5c9bab5

Browse files
committed
modsecurity: do not run for subreqs and after internal redirect
1 parent 251e9a7 commit 5c9bab5

4 files changed

+10
-4
lines changed

src/ngx_http_modsecurity_common.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ typedef struct {
7777

7878
unsigned waiting_more_body:1;
7979
unsigned body_requested:1;
80-
unsigned processed:1;
8180
unsigned logged:1;
8281
unsigned intervention_triggered:1;
8382
unsigned pre_access_processed:1;

src/ngx_http_modsecurity_header_filter.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,11 @@ ngx_http_modsecurity_header_filter(ngx_http_request_t *r)
5151

5252
ctx = ngx_http_get_module_ctx(r, ngx_http_modsecurity_module);
5353

54-
if (ctx == NULL || ctx->processed || ctx->intervention_triggered) {
54+
if (ctx == NULL || ctx->intervention_triggered) {
5555
// nothing to be done
5656
return ngx_http_next_header_filter(r);
5757
}
5858

59-
ctx->processed = 1;
60-
6159
part = &r->headers_out.headers.part;
6260
header = part->elts;
6361

@@ -99,6 +97,7 @@ ngx_http_modsecurity_header_filter(ngx_http_request_t *r)
9997
return ngx_http_next_header_filter(r);
10098
}
10199
if (rc > 0) {
100+
ctx->intervention_triggered = 1;
102101
return ngx_http_filter_finalize_request(r, &ngx_http_modsecurity_module, rc);
103102
}
104103

src/ngx_http_modsecurity_pre_access.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ ngx_http_modsecurity_pre_access_handler(ngx_http_request_t *r)
4545
ngx_pool_t *old_pool;
4646
ngx_http_modsecurity_ctx_t *ctx;
4747

48+
if (r != r->main || r->internal) {
49+
return NGX_DECLINED;
50+
}
51+
4852
ctx = ngx_http_get_module_ctx(r, ngx_http_modsecurity_module);
4953

5054
if (ctx == NULL

src/ngx_http_modsecurity_rewrite.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ ngx_http_modsecurity_rewrite_handler_internal(ngx_http_request_t *r)
5151
ngx_http_modsecurity_conf_t *mcf;
5252
ngx_http_modsecurity_main_conf_t *mmcf;
5353

54+
if (r != r->main || r->internal) {
55+
return NGX_DECLINED;
56+
}
57+
5458
/*
5559
if (r->method != NGX_HTTP_GET &&
5660
r->method != NGX_HTTP_POST && r->method != NGX_HTTP_HEAD) {

0 commit comments

Comments
 (0)