Skip to content

Commit 7f67820

Browse files
committed
Add separated config for internal redirect tests
1 parent 992cf3b commit 7f67820

File tree

3 files changed

+173
-0
lines changed

3 files changed

+173
-0
lines changed

.github/nginx/docs/403.html

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<html>
2+
<head>
3+
<title>403</title>
4+
</head>
5+
6+
<body>
7+
Forbidden 403 - custom error page.
8+
</body>
9+
</html>
10+

.github/nginx/nginx.conf.redir

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
user www-data;
2+
worker_processes auto;
3+
pid /run/nginx.pid;
4+
worker_cpu_affinity auto;
5+
6+
#working_directory /tmp/cores/;
7+
worker_rlimit_core 2000M;
8+
debug_points abort;
9+
10+
#load_module /usr/local/nginx/modules/ngx_http_modsecurity_module.so;
11+
12+
events {
13+
worker_connections 768;
14+
# multi_accept on;
15+
# use epoll;
16+
}
17+
18+
worker_rlimit_nofile 33268;
19+
20+
#daemon off;
21+
#master_process off;
22+
23+
http {
24+
25+
##
26+
# Basic Settings
27+
##
28+
29+
types_hash_max_size 2048;
30+
31+
server_names_hash_bucket_size 64;
32+
33+
include mime.types;
34+
default_type application/octet-stream;
35+
36+
##
37+
# Logging Settings
38+
##
39+
40+
#access_log /dev/stdout;
41+
#error_log /dev/stdout info;
42+
access_log /usr/local/nginx/logs/access.log;
43+
error_log /usr/local/nginx/logs/error.log info;
44+
45+
server_tokens off;
46+
47+
proxy_hide_header X-Powered-By;
48+
49+
modsecurity on;
50+
51+
server {
52+
listen 80;
53+
server_name modsectest1;
54+
55+
modsecurity on;
56+
modsecurity_rules_file /home/runner/work/ModSecurity-nginx/ModSecurity-nginx/ModSecurity-nginx/.github/nginx/modsecurity.conf;
57+
root /usr/local/nginx/html/;
58+
59+
error_page 403 /403.html;
60+
61+
location /403.html {
62+
internal;
63+
}
64+
65+
location / {
66+
try_files $uri /index.html;
67+
}
68+
}
69+
70+
server {
71+
listen 80;
72+
server_name modsectest2;
73+
74+
modsecurity on;
75+
modsecurity_rules_file /home/runner/work/ModSecurity-nginx/ModSecurity-nginx/ModSecurity-nginx/.github/nginx/modsecurity.conf;
76+
root /usr/local/nginx/html/;
77+
78+
error_page 403 /403.html;
79+
80+
location /403.html {
81+
internal;
82+
}
83+
84+
location / {
85+
try_files $uri /index.html;
86+
}
87+
}
88+
89+
}
90+

.github/workflows/test.yml

+73
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,79 @@ jobs:
142142
echo "FAIL"
143143
exit 1
144144
fi
145+
- name: Start Nginx with redir
146+
run: |
147+
sudo killall nginx
148+
sudo /usr/local/nginx/sbin/nginx -c /home/runner/work/ModSecurity-nginx/ModSecurity-nginx/ModSecurity-nginx/.github/nginx/nginx.conf.redir
149+
- name: Run attack test vhost 1
150+
run: |
151+
status=$(curl -sSo /dev/null -w %{http_code} -I -X GET -H "Host: modsectest1" "http://localhost/?q=attack")
152+
if [ "${status}" == "403" ]; then
153+
echo "OK"
154+
else
155+
echo "FAIL"
156+
exit 1
157+
fi
158+
- name: Run non-attack test vhost 1 (redir config)
159+
run: |
160+
status=$(curl -sSo /dev/null -w %{http_code} -I -X GET -H "Host: modsectest1" "http://localhost/?q=1")
161+
if [ "${status}" == "200" ]; then
162+
echo "OK"
163+
else
164+
echo "FAIL"
165+
exit 1
166+
fi
167+
- name: Run attack test vhost 2 (redir config)
168+
run: |
169+
status=$(curl -sSo /dev/null -w %{http_code} -I -X GET -H "Host: modsectest2" "http://localhost/?q=attack")
170+
if [ "${status}" == "403" ]; then
171+
echo "OK"
172+
else
173+
echo "FAIL"
174+
exit 1
175+
fi
176+
- name: Run non-attack test vhost 2 (redir config)
177+
run: |
178+
status=$(curl -sSo /dev/null -w %{http_code} -I -X GET -H "Host: modsectest2" "http://localhost/?q=1")
179+
if [ "${status}" == "200" ]; then
180+
echo "OK"
181+
else
182+
echo "FAIL"
183+
exit 1
184+
fi
185+
- name: Run file consistency check 1 (redir config)
186+
run: |
187+
curl -sS "http://localhost/data50k.json" --output data50k.json
188+
if [ -f data50k.json ]; then
189+
diff data50k.json /usr/local/nginx/html/data50k.json > /dev/null
190+
if [ $? -eq 0 ]; then
191+
ls -l data50k.json /usr/local/nginx/html/data50k.json
192+
echo "OK"
193+
else
194+
echo "FAIL"
195+
exit 2
196+
fi
197+
else
198+
echo "FAIL"
199+
exit 1
200+
fi
201+
- name: Run file consistency check 2 (redir config)
202+
run: |
203+
curl -sS "http://localhost/plugged.png" --output plugged.png
204+
if [ -f plugged.png ]; then
205+
diff plugged.png /usr/local/nginx/html/plugged.png > /dev/null
206+
if [ $? -eq 0 ]; then
207+
ls -l plugged.png /usr/local/nginx/html/plugged.png
208+
echo "OK"
209+
else
210+
echo "FAIL"
211+
exit 2
212+
fi
213+
else
214+
echo "FAIL"
215+
exit 1
216+
fi
217+
145218
146219
147220
build-windows:

0 commit comments

Comments
 (0)