Skip to content

Commit 1d436fd

Browse files
authored
Merge pull request #2273 from Vincevrp/vhost-anomaly-override
Allow overriding CRS anomaly threshold per vhost
2 parents 568ffa0 + 38a3873 commit 1d436fd

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

manifests/vhost.pp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,16 @@
552552
# If none of those parameters are set, the global audit log is used
553553
# (`/var/log/httpd/modsec\_audit.log`; Debian and derivatives: `/var/log/apache2/modsec\_audit.log`; others: ).
554554
#
555+
# @param modsec_inbound_anomaly_threshold
556+
# Override the global scoring threshold level of the inbound blocking rules
557+
# for the Collaborative Detection Mode in the OWASP ModSecurity Core Rule
558+
# Set.
559+
#
560+
# @param modsec_outbound_anomaly_threshold
561+
# Override the global scoring threshold level of the outbound blocking rules
562+
# for the Collaborative Detection Mode in the OWASP ModSecurity Core Rule
563+
# Set.
564+
#
555565
# @param no_proxy_uris
556566
# Specifies URLs you do not want to proxy. This parameter is meant to be used in combination
557567
# with [`proxy_dest`](#proxy_dest).
@@ -1901,6 +1911,8 @@
19011911
Optional[Variant[Hash, Array]] $modsec_disable_msgs = undef,
19021912
Optional[Variant[Hash, Array]] $modsec_disable_tags = undef,
19031913
Optional[String] $modsec_body_limit = undef,
1914+
Optional[Integer[1, default]] $modsec_inbound_anomaly_threshold = undef,
1915+
Optional[Integer[1, default]] $modsec_outbound_anomaly_threshold = undef,
19041916
Array[Hash] $jk_mounts = [],
19051917
Boolean $auth_kerb = false,
19061918
Enum['on', 'off'] $krb_method_negotiate = 'on',
@@ -2786,7 +2798,9 @@
27862798
# - $modsec_disable_tags
27872799
# - $modsec_body_limit
27882800
# - $modsec_audit_log_destination
2789-
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 {
2801+
# - $modsec_inbound_anomaly_threshold
2802+
# - $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) {
27902804
concat::fragment { "${name}-security":
27912805
target => "${priority_real}${filename}.conf",
27922806
order => 320,

spec/defines/vhost_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,33 @@
12021202
)
12031203
}
12041204
end
1205+
1206+
context 'modsec_anomaly_threshold' do
1207+
let :params do
1208+
{
1209+
'docroot' => '/rspec/docroot',
1210+
'modsec_inbound_anomaly_threshold' => 10_000,
1211+
'modsec_outbound_anomaly_threshold' => 10_000,
1212+
}
1213+
end
1214+
1215+
it { is_expected.to compile }
1216+
it {
1217+
is_expected.to contain_concat__fragment('rspec.example.com-security').with(
1218+
content: %r{
1219+
^\s+SecAction\ \\\n
1220+
\s+\"id:900110,\\\n
1221+
\s+phase:1,\\\n
1222+
\s+nolog,\\\n
1223+
\s+pass,\\\n
1224+
\s+t:none,\\\n
1225+
\s+setvar:tx.inbound_anomaly_score_threshold=10000,\ \\\n
1226+
\s+setvar:tx.outbound_anomaly_score_threshold=10000"$
1227+
}x,
1228+
)
1229+
}
1230+
end
1231+
12051232
context 'set only aliases' do
12061233
let :params do
12071234
{

templates/vhost/_security.erb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,14 @@
3939
<% if @modsec_body_limit -%>
4040
SecRequestBodyLimit <%= @modsec_body_limit %>
4141
<% end -%>
42+
<% if @modsec_inbound_anomaly_threshold and @modsec_outbound_anomaly_threshold -%>
43+
SecAction \
44+
"id:900110,\
45+
phase:1,\
46+
nolog,\
47+
pass,\
48+
t:none,\
49+
setvar:tx.inbound_anomaly_score_threshold=<%= @modsec_inbound_anomaly_threshold -%>, \
50+
setvar:tx.outbound_anomaly_score_threshold=<%= @modsec_outbound_anomaly_threshold -%>"
51+
<% end -%>
4252
</IfModule>

0 commit comments

Comments
 (0)