@@ -63,7 +63,11 @@ http {
63
63
modsecurity on;
64
64
modsecurity_rules '
65
65
SecRuleEngine On
66
- SecRule ARGS "@streq root" "id:10,phase:1,auditlog,status:403,deny"
66
+ SecResponseBodyAccess On
67
+ SecRule ARGS:phase1 "@streq BAD" "id:10,phase:1,auditlog,status:403,deny"
68
+ SecRule ARGS:phase2 "@streq BAD" "id:11,phase:2,auditlog,status:403,deny"
69
+ SecRule ARGS:phase3 "@streq BAD" "id:12,phase:3,auditlog,status:403,deny"
70
+ SecRule ARGS:phase4 "@streq BAD" "id:13,phase:4,auditlog,status:403,deny"
67
71
SecDebugLog %%TESTDIR%%/auditlog-debug-location.txt
68
72
SecDebugLogLevel 9
69
73
SecAuditEngine RelevantOnly
@@ -82,7 +86,11 @@ http {
82
86
modsecurity on;
83
87
modsecurity_rules '
84
88
SecRuleEngine On
85
- SecRule ARGS "@streq root" "id:10,phase:1,auditlog,status:403,deny"
89
+ SecResponseBodyAccess On
90
+ SecRule ARGS:phase1 "@streq BAD" "id:10,phase:1,auditlog,status:403,deny"
91
+ SecRule ARGS:phase2 "@streq BAD" "id:11,phase:2,auditlog,status:403,deny"
92
+ SecRule ARGS:phase3 "@streq BAD" "id:12,phase:3,auditlog,status:403,deny"
93
+ SecRule ARGS:phase4 "@streq BAD" "id:13,phase:4,auditlog,status:403,deny"
86
94
SecDebugLog %%TESTDIR%%/auditlog-debug-server.txt
87
95
SecDebugLogLevel 9
88
96
SecAuditEngine RelevantOnly
@@ -112,25 +120,23 @@ $t->write_file("/index.html", $index_txt);
112
120
my $error_txt = " This is a custom error page." ;
113
121
$t -> write_file(" /error.html" , $error_txt );
114
122
123
+ $t -> todo_alerts();
115
124
$t -> run();
116
- $t -> plan(10 );
125
+ $t -> plan(32 );
117
126
118
127
# ##############################################################################
119
128
120
129
my $d = $t -> testdir();
121
130
122
- my $t1 ;
123
- my $t2 ;
124
- my $t3 ;
125
- my $t4 ;
126
-
127
131
# Performing requests to a server with ModSecurity enabled at location context
128
- $t1 = http_get_host(' s1' , ' /?what=root' );
129
- $t2 = http_get_host(' s1' , ' /?what=other' );
130
-
131
- # Performing requests to a server with ModSecurity enabled at server context
132
- $t3 = http_get_host(' s2' , ' /?what=root' );
133
- $t4 = http_get_host(' s2' , ' /?what=other' );
132
+ like(http_get_host(' s1' , ' /?phase1=BAD' ), qr /$error_txt / , ' location context, phase 1, error page' );
133
+ like(http_get_host(' s1' , ' /?phase1=GOOD' ), qr /$index_txt / , ' location context, phase 1, index page' );
134
+ like(http_get_host(' s1' , ' /?phase2=BAD' ), qr /$error_txt / , ' location context, phase 2, error page' );
135
+ like(http_get_host(' s1' , ' /?phase2=GOOD' ), qr /$index_txt / , ' location context, phase 2, index page' );
136
+ like(http_get_host(' s1' , ' /?phase3=BAD' ), qr /$error_txt / , ' location context, phase 3, error page' );
137
+ like(http_get_host(' s1' , ' /?phase3=GOOD' ), qr /$index_txt / , ' location context, phase 3, index page' );
138
+ is(http_get_host(' s1' , ' /?phase4=BAD' ), ' ' , ' location context, phase 4, drop' );
139
+ like(http_get_host(' s1' , ' /?phase4=GOOD' ), qr /$index_txt / , ' location context, phase 4, index page' );
134
140
135
141
my $auditlog_location = do {
136
142
local $/ = undef ;
@@ -139,25 +145,40 @@ my $auditlog_location = do {
139
145
<$fh >;
140
146
};
141
147
148
+ like($auditlog_location , qr / phase1=BAD/ , ' location context, phase 1, BAD in auditlog' );
149
+ unlike($auditlog_location , qr / phase1=GOOD/ , ' location context, phase 1, GOOD not in auditlog' );
150
+ like($auditlog_location , qr / phase2=BAD/ , ' location context, phase 2, BAD in auditlog' );
151
+ unlike($auditlog_location , qr / phase2=GOOD/ , ' location context, phase 2, GOOD not in auditlog' );
152
+ like($auditlog_location , qr / phase3=BAD/ , ' location context, phase 3, BAD in auditlog' );
153
+ unlike($auditlog_location , qr / phase3=GOOD/ , ' location context, phase 3, GOOD not in auditlog' );
154
+ like($auditlog_location , qr / phase4=BAD/ , ' location context, phase 4, BAD in auditlog' );
155
+ unlike($auditlog_location , qr / phase4=GOOD/ , ' location context, phase 4, GOOD not in auditlog' );
156
+
157
+ # Performing requests to a server with ModSecurity enabled at server context
158
+ like(http_get_host(' s2' , ' /?phase1=BAD' ), qr /$error_txt / , ' server context, phase 1, error page' );
159
+ like(http_get_host(' s2' , ' /?phase1=GOOD' ), qr /$index_txt / , ' server context, phase 1, index page' );
160
+ like(http_get_host(' s2' , ' /?phase2=BAD' ), qr /$error_txt / , ' server context, phase 2, error page' );
161
+ like(http_get_host(' s2' , ' /?phase2=GOOD' ), qr /$index_txt / , ' server context, phase 2, index page' );
162
+ like(http_get_host(' s2' , ' /?phase3=BAD' ), qr /$error_txt / , ' server context, phase 3, error page' );
163
+ like(http_get_host(' s2' , ' /?phase3=GOOD' ), qr /$index_txt / , ' server context, phase 3, index page' );
164
+ is(http_get_host(' s2' , ' /?phase4=BAD' ), ' ' , ' server context, phase 4, drop' );
165
+ like(http_get_host(' s2' , ' /?phase4=GOOD' ), qr /$index_txt / , ' server context, phase 4, index page' );
166
+
142
167
my $auditlog_server = do {
143
168
local $/ = undef ;
144
169
open my $fh , " <" , " $d /auditlog-server.txt"
145
170
or die " could not open: $! " ;
146
171
<$fh >;
147
172
};
148
173
149
- like($t1 , qr /$error_txt / , ' ModSecurity at location / root' );
150
- like($t2 , qr /$index_txt / , ' ModSecurity at location / other' );
151
- like($auditlog_location , qr / what=root/ , ' ModSecurity at location / root present in auditlog' );
152
- unlike($auditlog_location , qr / what=other/ , ' ModSecurity at location / other not present in auditlog' );
153
-
154
- like($t3 , qr /$error_txt / , ' ModSecurity at server / root' );
155
- like($t4 , qr /$index_txt / , ' ModSecurity at server / other' );
156
- like($auditlog_server , qr / what=root/ , ' ModSecurity at server / root present in auditlog' );
157
- unlike($auditlog_server , qr / what=other/ , ' ModSecurity at server / other not present in auditlog' );
158
-
159
- like($auditlog_location , qr / Access denied with code 403/ , ' ModSecurity at location / 403 in auditlog' );
160
- like($auditlog_server , qr / Access denied with code 403/ , ' ModSecurity at server / 403 in auditlog' );
174
+ like($auditlog_server , qr / phase1=BAD/ , ' server context, phase 1, BAD in auditlog' );
175
+ unlike($auditlog_server , qr / phase1=GOOD/ , ' server context, phase 1, GOOD not in auditlog' );
176
+ like($auditlog_server , qr / phase2=BAD/ , ' server context, phase 2, BAD in auditlog' );
177
+ unlike($auditlog_server , qr / phase2=GOOD/ , ' server context, phase 2, GOOD not in auditlog' );
178
+ like($auditlog_server , qr / phase3=BAD/ , ' server context, phase 3, BAD in auditlog' );
179
+ unlike($auditlog_server , qr / phase3=GOOD/ , ' server context, phase 3, GOOD not in auditlog' );
180
+ like($auditlog_server , qr / phase4=BAD/ , ' server context, phase 4, BAD in auditlog' );
181
+ unlike($auditlog_server , qr / phase4=GOOD/ , ' server context, phase 4, GOOD not in auditlog' );
161
182
162
183
# ##############################################################################
163
184
0 commit comments