Skip to content

Commit c467cf4

Browse files
authored
Merge pull request #2274 from Vincevrp/vhost-allowed-methods
Allow overriding CRS allowed HTTP methods per vhost
2 parents 1d436fd + 54d08fa commit c467cf4

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

manifests/vhost.pp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,9 @@
562562
# for the Collaborative Detection Mode in the OWASP ModSecurity Core Rule
563563
# Set.
564564
#
565+
# @param modsec_allowed_methods
566+
# Override global allowed methods. A space-separated list of allowed HTTP methods.
567+
#
565568
# @param no_proxy_uris
566569
# Specifies URLs you do not want to proxy. This parameter is meant to be used in combination
567570
# with [`proxy_dest`](#proxy_dest).
@@ -1913,6 +1916,7 @@
19131916
Optional[String] $modsec_body_limit = undef,
19141917
Optional[Integer[1, default]] $modsec_inbound_anomaly_threshold = undef,
19151918
Optional[Integer[1, default]] $modsec_outbound_anomaly_threshold = undef,
1919+
Optional[String] $modsec_allowed_methods = undef,
19161920
Array[Hash] $jk_mounts = [],
19171921
Boolean $auth_kerb = false,
19181922
Enum['on', 'off'] $krb_method_negotiate = 'on',
@@ -2800,7 +2804,8 @@
28002804
# - $modsec_audit_log_destination
28012805
# - $modsec_inbound_anomaly_threshold
28022806
# - $modsec_outbound_anomaly_threshold
2803-
if $modsec_disable_vhost or $modsec_disable_ids or !empty($modsec_disable_ips) or $modsec_disable_msgs or $modsec_disable_tags or $modsec_audit_log_destination or ($modsec_inbound_anomaly_threshold and $modsec_outbound_anomaly_threshold) {
2807+
# - $modsec_allowed_methods
2808+
if $modsec_disable_vhost or $modsec_disable_ids or !empty($modsec_disable_ips) or $modsec_disable_msgs or $modsec_disable_tags or $modsec_audit_log_destination or ($modsec_inbound_anomaly_threshold and $modsec_outbound_anomaly_threshold) or $modsec_allowed_methods {
28042809
concat::fragment { "${name}-security":
28052810
target => "${priority_real}${filename}.conf",
28062811
order => 320,

spec/defines/vhost_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,29 @@
12291229
}
12301230
end
12311231

1232+
context 'modsec_allowed_methods' do
1233+
let :params do
1234+
{
1235+
'docroot' => '/rspec/docroot',
1236+
'modsec_allowed_methods' => 'GET HEAD POST OPTIONS',
1237+
}
1238+
end
1239+
1240+
it { is_expected.to compile }
1241+
it {
1242+
is_expected.to contain_concat__fragment('rspec.example.com-security').with(
1243+
content: %r{
1244+
^\s+SecAction\ \\\n
1245+
\s+\"id:900200,\\\n
1246+
\s+phase:1,\\\n
1247+
\s+nolog,\\\n\s+pass,\\\n
1248+
\s+t:none,\\\n
1249+
\s+setvar:'tx.allowed_methods=GET\ HEAD\ POST\ OPTIONS'"$
1250+
}x,
1251+
)
1252+
}
1253+
end
1254+
12321255
context 'set only aliases' do
12331256
let :params do
12341257
{

templates/vhost/_security.erb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,13 @@
4949
setvar:tx.inbound_anomaly_score_threshold=<%= @modsec_inbound_anomaly_threshold -%>, \
5050
setvar:tx.outbound_anomaly_score_threshold=<%= @modsec_outbound_anomaly_threshold -%>"
5151
<% end -%>
52+
<% if @modsec_allowed_methods -%>
53+
SecAction \
54+
"id:900200,\
55+
phase:1,\
56+
nolog,\
57+
pass,\
58+
t:none,\
59+
setvar:'tx.allowed_methods=<%= @modsec_allowed_methods -%>'"
60+
<% end -%>
5261
</IfModule>

0 commit comments

Comments
 (0)