Skip to content

Commit bc9dc3e

Browse files
authored
Merge pull request #2280 from Vincevrp/dos-protection
Parameterize CRS DOS protection
2 parents 92c47e1 + f9d79d1 commit bc9dc3e

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed

manifests/mod/security.pp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,24 @@
104104
# @param manage_security_crs
105105
# Toggles whether to manage ModSecurity Core Rule Set
106106
#
107+
# @param enable_dos_protection
108+
# Toggles the optional OWASP ModSecurity Core Rule Set DOS protection rule
109+
# (rule id 900700)
110+
#
111+
# @param dos_burst_time_slice
112+
# Configures time in which a burst is measured for the OWASP ModSecurity Core Rule Set DOS protection rule
113+
# (rule id 900700)
114+
#
115+
# @param dos_counter_threshold
116+
# Configures the amount of requests that can be made within dos_burst_time_slice before it is considered a burst in
117+
# the OWASP ModSecurity Core Rule Set DOS protection rule (rule id 900700)
118+
#
119+
# @param dos_block_timeout
120+
# Configures how long the client should be blocked when the dos_counter_threshold is exceeded in the OWASP
121+
# ModSecurity Core Rule Set DOS protection rule (rule id 900700)
122+
#
107123
# @see https://github.com/SpiderLabs/ModSecurity/wiki for additional documentation.
124+
# @see https://coreruleset.org/docs/ for addional documentation
108125
#
109126
class apache::mod::security (
110127
Stdlib::Absolutepath $logroot = $apache::params::logroot,
@@ -141,6 +158,10 @@
141158
Enum['On', 'Off'] $secrequestbodyaccess = 'On',
142159
Enum['On', 'Off'] $secresponsebodyaccess = 'Off',
143160
Boolean $manage_security_crs = true,
161+
Boolean $enable_dos_protection = true,
162+
Integer[1, default] $dos_burst_time_slice = 60,
163+
Integer[1, default] $dos_counter_threshold = 100,
164+
Integer[1, default] $dos_block_timeout = 600,
144165
) inherits apache::params {
145166
include apache
146167

@@ -278,6 +299,10 @@
278299
# - $restricted_extensions
279300
# - $restricted_headers
280301
# - $secrequestmaxnumargs
302+
# - $enable_dos_protection
303+
# - $dos_burst_time_slice
304+
# - $dos_counter_threshold
305+
# - $dos_block_timeout
281306
file { "${modsec_dir}/security_crs.conf":
282307
ensure => file,
283308
content => template('apache/mod/security_crs.conf.erb'),

spec/classes/mod/security_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@
140140
{
141141
paranoia_level: 1,
142142
executing_paranoia_level: 2,
143+
enable_dos_protection: true,
144+
dos_burst_time_slice: 30,
145+
dos_counter_threshold: 120,
146+
dos_block_timeout: 300,
143147
}
144148
end
145149

@@ -148,6 +152,18 @@
148152
%r{^SecAction \\\n\s+\"id:900000,\\\n\s+phase:1,\\\n\s+nolog,\\\n\s+pass,\\\n\s+t:none,\\\n\s+setvar:tx.paranoia_level=1"$}
149153
is_expected.to contain_file('/etc/httpd/modsecurity.d/security_crs.conf').with_content \
150154
%r{^SecAction \\\n\s+\"id:900001,\\\n\s+phase:1,\\\n\s+nolog,\\\n\s+pass,\\\n\s+t:none,\\\n\s+setvar:tx.executing_paranoia_level=2"$}
155+
is_expected.to contain_file('/etc/httpd/modsecurity.d/security_crs.conf').with_content \
156+
%r{
157+
^SecAction\ \\\n
158+
\s+\"id:900700,\\\n
159+
\s+phase:1,\\\n
160+
\s+nolog,\\\n
161+
\s+pass,\\\n
162+
\s+t:none,\\\n
163+
\s+setvar:'tx.dos_burst_time_slice=30',\\\n
164+
\s+setvar:'tx.dos_counter_threshold=120',\\\n
165+
\s+setvar:'tx.dos_block_timeout=300'"$
166+
}x
151167
}
152168
end
153169

@@ -302,6 +318,10 @@
302318
{
303319
paranoia_level: 1,
304320
executing_paranoia_level: 1,
321+
enable_dos_protection: true,
322+
dos_burst_time_slice: 30,
323+
dos_counter_threshold: 120,
324+
dos_block_timeout: 300,
305325
}
306326
end
307327

@@ -310,6 +330,18 @@
310330
%r{^SecAction \\\n\s+\"id:900000,\\\n\s+phase:1,\\\n\s+nolog,\\\n\s+pass,\\\n\s+t:none,\\\n\s+setvar:tx.paranoia_level=1"$}
311331
is_expected.to contain_file('/etc/modsecurity/security_crs.conf').with_content \
312332
%r{^SecAction \\\n\s+\"id:900001,\\\n\s+phase:1,\\\n\s+nolog,\\\n\s+pass,\\\n\s+t:none,\\\n\s+setvar:tx.executing_paranoia_level=1"$}
333+
is_expected.to contain_file('/etc/modsecurity/security_crs.conf').with_content \
334+
%r{
335+
^SecAction\ \\\n
336+
\s+\"id:900700,\\\n
337+
\s+phase:1,\\\n
338+
\s+nolog,\\\n
339+
\s+pass,\\\n
340+
\s+t:none,\\\n
341+
\s+setvar:'tx.dos_burst_time_slice=30',\\\n
342+
\s+setvar:'tx.dos_counter_threshold=120',\\\n
343+
\s+setvar:'tx.dos_block_timeout=300'"$
344+
}x
313345
}
314346
end
315347

templates/mod/security_crs.conf.erb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -714,16 +714,17 @@ SecAction \
714714
#
715715
# Uncomment this rule to use this feature:
716716
#
717+
<% if @enable_dos_protection -%>
717718
SecAction \
718719
"id:900700,\
719720
phase:1,\
720721
nolog,\
721722
pass,\
722723
t:none,\
723-
setvar:'tx.dos_burst_time_slice=60',\
724-
setvar:'tx.dos_counter_threshold=100',\
725-
setvar:'tx.dos_block_timeout=600'"
726-
724+
setvar:'tx.dos_burst_time_slice=<%= @dos_burst_time_slice %>',\
725+
setvar:'tx.dos_counter_threshold=<%= @dos_counter_threshold %>',\
726+
setvar:'tx.dos_block_timeout=<%= @dos_block_timeout %>'"
727+
<% end -%>
727728

728729
#
729730
# -- [[ Check UTF-8 encoding ]] ------------------------------------------------

0 commit comments

Comments
 (0)