Skip to content

Commit e028ca4

Browse files
committed
Use ngx_http_filter_finalize_request() on intervention in header filter
Closes #238.
1 parent 0bf1355 commit e028ca4

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

CHANGES

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
v1.0.x - YYYY-MMM-DD (To be released)
22
-------------------------------------
33

4+
- Fix nginx sends response without headers
5+
[Issue #238 - @airween, @defanator]
46
- Fix nginx not clearing body cache (caused by incomplete fix for #187)
57
[Issue #216 - @krewi1, @martinhsv]
68
- Fix config setting not respected: client_body_in_file_only on

src/ngx_http_modsecurity_header_filter.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,9 @@ ngx_http_modsecurity_header_filter(ngx_http_request_t *r)
525525
ret = ngx_http_modsecurity_process_intervention(ctx->modsec_transaction, r);
526526
if (r->error_page) {
527527
return ngx_http_next_header_filter(r);
528-
}
528+
}
529529
if (ret > 0) {
530-
return ret;
530+
return ngx_http_filter_finalize_request(r, &ngx_http_modsecurity_module, ret);
531531
}
532532

533533
/*

tests/modsecurity.t

+21-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,23 @@ http {
105105
SecRule ARGS "@streq block403" "id:4,phase:4,status:403,block"
106106
';
107107
}
108+
location /early-block {
109+
modsecurity on;
110+
modsecurity_rules '
111+
SecRuleEngine On
112+
SecResponseBodyAccess On
113+
SecDefaultAction "phase:1,log,auditlog,pass"
114+
SecDefaultAction "phase:2,log,auditlog,pass"
115+
SecAction "id:900101,phase:1,nolog,pass,t:none,setvar:tx.trigger_phase1=1"
116+
SecAction "id:900103,phase:1,nolog,pass,t:none,setvar:tx.trigger_phase3=1"
117+
SecAction "id:900105,phase:1,nolog,pass,t:none,setvar:tx.trigger_phase5=1"
118+
SecRule TX:TRIGGER_PHASE1 "@eq 1" "id:901111,phase:1,t:none,deny,log"
119+
SecRule REQUEST_BODY "@rx attack" "id:901121,phase:2,t:none,deny,log"
120+
SecRule TX:TRIGGER_PHASE3 "@eq 1" "id:901131,phase:3,t:none,deny,log"
121+
SecRule RESPONSE_BODY "@rx ok" "id:901141,phase:4,t:none,deny,log"
122+
SecRule TX:TRIGGER_PHASE5 "@eq 1" "id:901151,phase:5,t:none,pass,log,msg:\'This is the phase 5.\'"
123+
';
124+
}
108125
}
109126
}
110127
EOF
@@ -113,9 +130,10 @@ $t->write_file("/phase1", "should be moved/blocked before this.");
113130
$t->write_file("/phase2", "should be moved/blocked before this.");
114131
$t->write_file("/phase3", "should be moved/blocked before this.");
115132
$t->write_file("/phase4", "should not be moved/blocked, headers delivered before phase 4.");
133+
$t->write_file("/early-block", "should be moved/blocked before this.");
116134
$t->run();
117135
$t->todo_alerts();
118-
$t->plan(20);
136+
$t->plan(21);
119137

120138
###############################################################################
121139

@@ -150,3 +168,5 @@ like(http_get('/phase2?what=nothing'), qr/should be moved\/blocked before this./
150168
like(http_get('/phase3?what=nothing'), qr/should be moved\/blocked before this./, 'nothing phase 3');
151169
like(http_get('/phase4?what=nothing'), qr/should not be moved\/blocked, headers delivered before phase 4./, 'nothing phase 4');
152170

171+
# early block (https://github.com/SpiderLabs/ModSecurity-nginx/issues/238)
172+
like(http_get('/early-block'), qr/^HTTP.*403/, 'early block 403 (https://github.com/SpiderLabs/ModSecurity-nginx/issues/238)');

0 commit comments

Comments
 (0)