@@ -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}
110127EOF
@@ -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./
150168like(http_get(' /phase3?what=nothing' ), qr / should be moved\/ blocked before this./ , ' nothing phase 3' );
151169like(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