Skip to content

Commit 568ffa0

Browse files
authored
Merge pull request #2272 from Vincevrp/modsec-bodyaccess
Allow configuring SecRequestBodyAccess and SecResponseBodyAccess
2 parents fcd8be2 + e3f10c8 commit 568ffa0

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

manifests/mod/security.pp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@
9595
# @param secrequestbodyinmemorylimit
9696
# Configures the maximum request body size that ModSecurity will store in memory.
9797
#
98+
# @param secrequestbodyaccess
99+
# Toggle SecRequestBodyAccess On or Off
100+
#
101+
# @param secresponsebodyaccess
102+
# Toggle SecResponseBodyAccess On or Off
103+
#
98104
# @param manage_security_crs
99105
# Toggles whether to manage ModSecurity Core Rule Set
100106
#
@@ -132,6 +138,8 @@
132138
Integer $secrequestbodyinmemorylimit = 131072,
133139
Integer[1,4] $paranoia_level = 1,
134140
Integer[1,4] $executing_paranoia_level = $paranoia_level,
141+
Enum['On', 'Off'] $secrequestbodyaccess = 'On',
142+
Enum['On', 'Off'] $secresponsebodyaccess = 'Off',
135143
Boolean $manage_security_crs = true,
136144
) inherits apache::params {
137145
include apache
@@ -197,6 +205,8 @@
197205
# - secrequestbodylimit
198206
# - secrequestbodynofileslimit
199207
# - secrequestbodyinmemorylimit
208+
# - secrequestbodyaccess
209+
# - secresponsebodyaccess
200210
file { 'security.conf':
201211
ensure => file,
202212
content => template('apache/mod/security.conf.erb'),

spec/classes/mod/security_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,17 @@
7979
audit_log_type: 'Concurrent',
8080
audit_log_storage_dir: '/var/log/httpd/audit',
8181
secdefaultaction: 'deny,status:406,nolog,auditlog',
82+
secrequestbodyaccess: 'Off',
83+
secresponsebodyaccess: 'On',
8284
}
8385
end
8486

8587
it { is_expected.to contain_file('security.conf').with_content %r{^\s+SecAuditLogRelevantStatus "\^\(\?:5\|4\(\?!01\|04\)\)"$} }
8688
it { is_expected.to contain_file('security.conf').with_content %r{^\s+SecAuditLogParts ABCDZ$} }
8789
it { is_expected.to contain_file('security.conf').with_content %r{^\s+SecAuditLogType Concurrent$} }
8890
it { is_expected.to contain_file('security.conf').with_content %r{^\s+SecAuditLogStorageDir /var/log/httpd/audit$} }
91+
it { is_expected.to contain_file('security.conf').with_content %r{^\s+SecRequestBodyAccess Off$} }
92+
it { is_expected.to contain_file('security.conf').with_content %r{^\s+SecResponseBodyAccess On$} }
8993
it { is_expected.to contain_file('/etc/httpd/modsecurity.d/security_crs.conf').with_content %r{^\s*SecDefaultAction "phase:2,deny,status:406,nolog,auditlog"$} }
9094
it {
9195
is_expected.to contain_file('bar.conf').with(
@@ -227,6 +231,8 @@
227231
audit_log_type: 'Concurrent',
228232
audit_log_storage_dir: '/var/log/httpd/audit',
229233
secdefaultaction: 'deny,status:406,nolog,auditlog',
234+
secrequestbodyaccess: 'Off',
235+
secresponsebodyaccess: 'On',
230236
}
231237
end
232238

@@ -235,6 +241,8 @@
235241
it { is_expected.to contain_file('security.conf').with_content %r{^\s+SecAuditLogRelevantStatus "\^\(\?:5\|4\(\?!01\|04\)\)"$} }
236242
it { is_expected.to contain_file('security.conf').with_content %r{^\s+SecAuditLogParts ABCDZ$} }
237243
it { is_expected.to contain_file('security.conf').with_content %r{^\s+SecAuditLogStorageDir /var/log/httpd/audit$} }
244+
it { is_expected.to contain_file('security.conf').with_content %r{^\s+SecRequestBodyAccess Off$} }
245+
it { is_expected.to contain_file('security.conf').with_content %r{^\s+SecResponseBodyAccess On$} }
238246
it { is_expected.to contain_file('/etc/modsecurity/security_crs.conf').with_content %r{^\s*SecDefaultAction "phase:2,deny,status:406,nolog,auditlog"$} }
239247
it {
240248
is_expected.to contain_file('bar.conf').with(

templates/mod/security.conf.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<IfModule mod_security2.c>
22
# Default recommended configuration
33
SecRuleEngine <%= @modsec_secruleengine %>
4-
SecRequestBodyAccess On
4+
SecRequestBodyAccess <%= @secrequestbodyaccess %>
55
<%- if @custom_rules -%>
66
Include <%= @modsec_dir %>/custom_rules/*.conf
77
<%- end -%>
@@ -40,7 +40,7 @@
4040
SecRule TX:/^MSC_/ "!@streq 0" \
4141
"id:'200004',phase:2,t:none,deny,msg:'ModSecurity internal error flagged: %{MATCHED_VAR_NAME}'"
4242

43-
SecResponseBodyAccess Off
43+
SecResponseBodyAccess <%= @secresponsebodyaccess %>
4444
SecResponseBodyMimeType text/plain text/html text/xml
4545
SecResponseBodyLimit 524288
4646
SecResponseBodyLimitAction ProcessPartial

0 commit comments

Comments
 (0)