Skip to content

Commit e1ea8e5

Browse files
authored
Merge pull request #3425 from airween/v2/regrtestfix
fix: mod_security2's regression tests fix
2 parents a4ea4e6 + fb4a346 commit e1ea8e5

16 files changed

+380
-354
lines changed

.gitignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,12 @@ m4/lt~obsolete.m4
108108
Makefile
109109

110110
# IDEs
111-
.idea
111+
.idea
112+
113+
# tests
114+
tests/regression/server_root/**
115+
tests/*.pl
116+
tests/*.trs
117+
tests/*.log
118+
119+

build/compile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#! /bin/sh
22
# Wrapper for compilers which do not understand '-c -o'.
33

4-
scriptversion=2018-03-07.03; # UTC
4+
scriptversion=2024-06-19.01; # UTC
55

6-
# Copyright (C) 1999-2021 Free Software Foundation, Inc.
6+
# Copyright (C) 1999-2024 Free Software Foundation, Inc.
77
# Written by Tom Tromey <[email protected]>.
88
#
99
# This program is free software; you can redistribute it and/or modify
@@ -143,7 +143,7 @@ func_cl_wrapper ()
143143
# configure might choose to run compile as 'compile cc -o foo foo.c'.
144144
eat=1
145145
case $2 in
146-
*.o | *.[oO][bB][jJ])
146+
*.o | *.lo | *.[oO][bB][jJ])
147147
func_file_conv "$2"
148148
set x "$@" -Fo"$file"
149149
shift
@@ -248,14 +248,17 @@ If you are trying to build a whole package this is not the
248248
right script to run: please start by reading the file 'INSTALL'.
249249
250250
Report bugs to <[email protected]>.
251+
GNU Automake home page: <https://www.gnu.org/software/automake/>.
252+
General help using GNU software: <https://www.gnu.org/gethelp/>.
251253
EOF
252254
exit $?
253255
;;
254256
-v | --v*)
255-
echo "compile $scriptversion"
257+
echo "compile (GNU Automake) $scriptversion"
256258
exit $?
257259
;;
258260
cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \
261+
clang-cl | *[/\\]clang-cl | clang-cl.exe | *[/\\]clang-cl.exe | \
259262
icl | *[/\\]icl | icl.exe | *[/\\]icl.exe )
260263
func_cl_wrapper "$@" # Doesn't return...
261264
;;

configure.ac

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -946,9 +946,6 @@ AC_CONFIG_FILES([build/apxs-wrapper], [chmod +x build/apxs-wrapper])
946946
if test -e "$PERL"; then
947947
if test "$build_mlogc" -ne 0; then
948948
AC_CONFIG_FILES([mlogc/mlogc-batch-load.pl], [chmod +x mlogc/mlogc-batch-load.pl])
949-
AC_CONFIG_FILES([tests/regression/misc/40-secRemoteRules.t])
950-
AC_CONFIG_FILES([tests/regression/misc/50-ipmatchfromfile-external.t])
951-
AC_CONFIG_FILES([tests/regression/misc/60-pmfromfile-external.t])
952949
fi
953950
AC_CONFIG_FILES([tests/run-unit-tests.pl], [chmod +x tests/run-unit-tests.pl])
954951
AC_CONFIG_FILES([tests/run-regression-tests.pl], [chmod +x tests/run-regression-tests.pl])

tests/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ TESTS = $(check_SCRIPTS)
8080
test: check
8181

8282
test-regression: run-regression-tests.pl
83-
$(PERL) run-regression-tests.pl
83+
$(PERL) run-regression-tests.pl -S .
8484

8585
test-regression-nginx: run-regression-tests-nginx.pl
8686
$(PERL) run-regression-tests-nginx.pl

tests/modsecurity.conf-minimal

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
# -- Rule engine initialization ----------------------------------------------
2+
3+
# Enable ModSecurity, attaching it to every transaction. Use detection
4+
# only to start with, because that minimises the chances of post-installation
5+
# disruption.
6+
#
7+
SecRuleEngine DetectionOnly
8+
9+
10+
# -- Request body handling ---------------------------------------------------
11+
12+
# Allow ModSecurity to access request bodies. If you don't, ModSecurity
13+
# won't be able to see any POST parameters, which opens a large security
14+
# hole for attackers to exploit.
15+
#
16+
SecRequestBodyAccess On
17+
18+
19+
# Enable XML request body parser.
20+
# Initiate XML Processor in case of xml content-type
21+
#
22+
SecRule REQUEST_HEADERS:Content-Type "^(?:application(?:/soap\+|/)|text/)xml" \
23+
"id:'200000',phase:1,t:none,t:lowercase,pass,nolog,ctl:requestBodyProcessor=XML"
24+
25+
# Enable JSON request body parser.
26+
# Initiate JSON Processor in case of JSON content-type; change accordingly
27+
# if your application does not use 'application/json'
28+
#
29+
SecRule REQUEST_HEADERS:Content-Type "^application/json" \
30+
"id:'200001',phase:1,t:none,t:lowercase,pass,nolog,ctl:requestBodyProcessor=JSON"
31+
32+
# Sample rule to enable JSON request body parser for more subtypes.
33+
# Uncomment or adapt this rule if you want to engage the JSON
34+
# Processor for "+json" subtypes
35+
#
36+
#SecRule REQUEST_HEADERS:Content-Type "^application/[a-z0-9.-]+[+]json" \
37+
# "id:'200006',phase:1,t:none,t:lowercase,pass,nolog,ctl:requestBodyProcessor=JSON"
38+
39+
# Maximum request body size we will accept for buffering. If you support
40+
# file uploads then the value given on the first line has to be as large
41+
# as the largest file you are willing to accept. The second value refers
42+
# to the size of data, with files excluded. You want to keep that value as
43+
# low as practical.
44+
#
45+
SecRequestBodyLimit 13107200
46+
SecRequestBodyNoFilesLimit 131072
47+
48+
# Store up to 128 KB of request body data in memory. When the multipart
49+
# parser reaches this limit, it will start using your hard disk for
50+
# storage. That is slow, but unavoidable.
51+
#
52+
SecRequestBodyInMemoryLimit 131072
53+
54+
# What do do if the request body size is above our configured limit.
55+
# Keep in mind that this setting will automatically be set to ProcessPartial
56+
# when SecRuleEngine is set to DetectionOnly mode in order to minimize
57+
# disruptions when initially deploying ModSecurity.
58+
#
59+
SecRequestBodyLimitAction Reject
60+
61+
# Maximum parsing depth allowed for JSON objects. You want to keep this
62+
# value as low as practical.
63+
#
64+
SecRequestBodyJsonDepthLimit 512
65+
66+
# Verify that we've correctly processed the request body.
67+
# As a rule of thumb, when failing to process a request body
68+
# you should reject the request (when deployed in blocking mode)
69+
# or log a high-severity alert (when deployed in detection-only mode).
70+
#
71+
SecRule REQBODY_ERROR "!@eq 0" \
72+
"id:'200002', phase:2,t:none,log,deny,status:400,msg:'Failed to parse request body.',logdata:'%{reqbody_error_msg}',severity:2"
73+
74+
# By default be strict with what we accept in the multipart/form-data
75+
# request body. If the rule below proves to be too strict for your
76+
# environment consider changing it to detection-only. You are encouraged
77+
# _not_ to remove it altogether.
78+
#
79+
SecRule MULTIPART_STRICT_ERROR "!@eq 0" \
80+
"id:'200003',phase:2,t:none,log,deny,status:400, \
81+
msg:'Multipart request body failed strict validation: \
82+
PE %{REQBODY_PROCESSOR_ERROR}, \
83+
BQ %{MULTIPART_BOUNDARY_QUOTED}, \
84+
BW %{MULTIPART_BOUNDARY_WHITESPACE}, \
85+
DB %{MULTIPART_DATA_BEFORE}, \
86+
DA %{MULTIPART_DATA_AFTER}, \
87+
HF %{MULTIPART_HEADER_FOLDING}, \
88+
LF %{MULTIPART_LF_LINE}, \
89+
SM %{MULTIPART_MISSING_SEMICOLON}, \
90+
IQ %{MULTIPART_INVALID_QUOTING}, \
91+
IP %{MULTIPART_INVALID_PART}, \
92+
IH %{MULTIPART_INVALID_HEADER_FOLDING}, \
93+
FL %{MULTIPART_FILE_LIMIT_EXCEEDED}'"
94+
95+
# Did we see anything that might be a boundary?
96+
#
97+
SecRule MULTIPART_UNMATCHED_BOUNDARY "!@eq 0" \
98+
"id:'200004',phase:2,t:none,log,deny,msg:'Multipart parser detected a possible unmatched boundary.'"
99+
100+
# PCRE Tuning
101+
# We want to avoid a potential RegEx DoS condition
102+
#
103+
SecPcreMatchLimit 1000
104+
SecPcreMatchLimitRecursion 1000
105+
106+
# Some internal errors will set flags in TX and we will need to look for these.
107+
# All of these are prefixed with "MSC_". The following flags currently exist:
108+
#
109+
# MSC_PCRE_LIMITS_EXCEEDED: PCRE match limits were exceeded.
110+
#
111+
SecRule TX:/^MSC_/ "!@streq 0" \
112+
"id:'200005',phase:2,t:none,log,deny,msg:'ModSecurity internal error flagged: %{MATCHED_VAR_NAME}'"
113+
114+
115+
# -- Response body handling --------------------------------------------------
116+
117+
# Allow ModSecurity to access response bodies.
118+
# You should have this directive enabled in order to identify errors
119+
# and data leakage issues.
120+
#
121+
# Do keep in mind that enabling this directive does increases both
122+
# memory consumption and response latency.
123+
#
124+
SecResponseBodyAccess On
125+
126+
# Which response MIME types do you want to inspect? You should adjust the
127+
# configuration below to catch documents but avoid static files
128+
# (e.g., images and archives).
129+
#
130+
SecResponseBodyMimeType text/plain text/html text/xml
131+
132+
# Buffer response bodies of up to 512 KB in length.
133+
SecResponseBodyLimit 524288
134+
135+
# What happens when we encounter a response body larger than the configured
136+
# limit? By default, we process what we have and let the rest through.
137+
# That's somewhat less secure, but does not break any legitimate pages.
138+
#
139+
SecResponseBodyLimitAction ProcessPartial
140+
141+
142+
# -- Filesystem configuration ------------------------------------------------
143+
144+
# The location where ModSecurity stores temporary files (for example, when
145+
# it needs to handle a file upload that is larger than the configured limit).
146+
#
147+
# This default setting is chosen due to all systems have /tmp available however,
148+
# this is less than ideal. It is recommended that you specify a location that's private.
149+
#
150+
SecTmpDir /tmp/
151+
152+
# The location where ModSecurity will keep its persistent data. This default setting
153+
# is chosen due to all systems have /tmp available however, it
154+
# too should be updated to a place that other users can't access.
155+
#
156+
SecDataDir /tmp/
157+
158+
159+
# -- File uploads handling configuration -------------------------------------
160+
161+
# The location where ModSecurity stores intercepted uploaded files. This
162+
# location must be private to ModSecurity. You don't want other users on
163+
# the server to access the files, do you?
164+
#
165+
#SecUploadDir /opt/modsecurity/var/upload/
166+
167+
# By default, only keep the files that were determined to be unusual
168+
# in some way (by an external inspection script). For this to work you
169+
# will also need at least one file inspection rule.
170+
#
171+
#SecUploadKeepFiles RelevantOnly
172+
173+
# Uploaded files are by default created with permissions that do not allow
174+
# any other user to access them. You may need to relax that if you want to
175+
# interface ModSecurity to an external program (e.g., an anti-virus).
176+
#
177+
#SecUploadFileMode 0600
178+
179+
180+
# -- Debug log configuration -------------------------------------------------
181+
182+
# The default debug log configuration is to duplicate the error, warning
183+
# and notice messages from the error log.
184+
#
185+
#SecDebugLog /opt/modsecurity/var/log/debug.log
186+
#SecDebugLogLevel 3
187+
188+
189+
# -- Audit log configuration -------------------------------------------------
190+
191+
# Log the transactions that are marked by a rule, as well as those that
192+
# trigger a server error (determined by a 5xx or 4xx, excluding 404,
193+
# level response status codes).
194+
#
195+
SecAuditEngine RelevantOnly
196+
SecAuditLogRelevantStatus "^(?:5|4(?!04))"
197+
198+
# Log everything we know about a transaction.
199+
SecAuditLogParts ABIJDEFHZ
200+
201+
# Use a single file for logging. This is much easier to look at, but
202+
# assumes that you will use the audit log only ocassionally.
203+
#
204+
#SecAuditLogType Serial
205+
#SecAuditLog /var/log/modsec_audit.log
206+
207+
# Specify the path for concurrent audit logging.
208+
#SecAuditLogStorageDir /opt/modsecurity/var/audit/
209+
210+
211+
# -- Miscellaneous -----------------------------------------------------------
212+
213+
# Use the most commonly used application/x-www-form-urlencoded parameter
214+
# separator. There's probably only one application somewhere that uses
215+
# something else so don't expect to change this value.
216+
#
217+
SecArgumentSeparator &
218+
219+
# Settle on version 0 (zero) cookies, as that is what most applications
220+
# use. Using an incorrect cookie version may open your installation to
221+
# evasion attacks (against the rules that examine named cookies).
222+
#
223+
SecCookieFormat 0
224+
225+
# Specify your Unicode Code Point.
226+
# This mapping is used by the t:urlDecodeUni transformation function
227+
# to properly map encoded data to your language. Properly setting
228+
# these directives helps to reduce false positives and negatives.
229+
#
230+
SecUnicodeMapFile unicode.mapping 20127
231+
232+
# Improve the quality of ModSecurity by sharing information about your
233+
# current ModSecurity version and dependencies versions.
234+
# The following information will be shared: ModSecurity version,
235+
# Web Server version, APR version, PCRE version, Lua version, Libxml2
236+
# version, Anonymous unique id for host.
237+
# NB: As of April 2022, there is no longer any advantage to turning this
238+
# setting On, as there is no active receiver for the information.
239+
SecStatusEngine Off
240+

tests/regression/config/00-load-modsec.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
conf => sub {
1515
# Open the minimal conf file, substituting the
1616
# relative log paths with full paths.
17-
open(C, "<$ENV{DIST_ROOT}/modsecurity.conf-minimal") or die "$!\n";
17+
open(C, "<$ENV{DIST_ROOT}/tests/modsecurity.conf-minimal") or die "$!\n";
1818
(my $conf = join('', <C>)) =~ s#Log logs/#Log $ENV{TEST_SERVER_ROOT}/logs/#g;
1919
close C;
2020

tests/regression/config/10-misc-directives.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
error => [ qr/ModSecurity: Warning. Unconditional match in SecAction\./, 1 ],
5656
},
5757
match_file => {
58-
"$ENV{DATA_DIR}/ip.pag" => qr/\x00\x06dummy\x00\x00\x021\x00/,
58+
"$ENV{DATA_DIR}/$ENV{RUNASUSER}-ip.pag" => qr/\x00\x06dummy\x00\x00\x021\x00/,
5959
},
6060
match_response => {
6161
status => qr/^200$/,

tests/regression/config/10-request-directives.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,10 +578,10 @@
578578
SecRequestBodyLimit 131072
579579
),
580580
match_log => {
581-
-debug => [ qr/Request body is larger than the configured limit/, 1],
581+
error => [ qr/Multipart parsing error: Multipart: Final boundary missing./, 1],
582582
},
583583
match_response => {
584-
status => qr/^200$/,
584+
status => qr/^500$/,
585585
},
586586
request => normalize_raw_request_data(
587587
qq(

0 commit comments

Comments
 (0)