I have Ubuntu 18.10 with apache2
, libapache2-mod-security2
, modsecurity-crs
packages with their default configuration except for enabling ModSecurity debug logging and copying modsecurity.conf-recommended
and adding SecRuleEngine On
.
I added a new SecRule
to a separate file in /etc/modsecurity/
Content of /etc/modsecurity/sf4-modsec.conf
is only one line:
SecRule RESPONSE_BODY "@rx <script" id:1000137,phase:4,deny,log,status:403
I can confirm that this rule is being loaded as it appears in debug logs with phase:1
:
[02/May/2019:20:48:33 +0200] [localhost/sid#7f8e0d51a5c8][rid#7f8e108d20a0][/_profiler/empty/search/results][4] Recipe: Invoking rule 7f8e0d40d138; [file "/etc/modsecurity/sf4-modsec.conf"] [line "1"] [id "1000137"].
[02/May/2019:20:48:33 +0200] [localhost/sid#7f8e0d51a5c8][rid#7f8e108d20a0][/_profiler/empty/search/results][5] Rule 7f8e0d40d138: SecRule "RESPONSE_BODY" "@rx <script>" "phase:1,auditlog,id:1000137,deny,log,status:403"
[02/May/2019:20:48:33 +0200] [localhost/sid#7f8e0d51a5c8][rid#7f8e108d20a0][/_profiler/empty/search/results][4] Rule returned 0.
[02/May/2019:20:48:33 +0200] [localhost/sid#7f8e0d51a5c8][rid#7f8e108d20a0][/_profiler/empty/search/results][9] No match, not chained -> mode NEXT_RULE.
[02/May/2019:20:48:33 +0200] [localhost/sid#7f8e0d51a5c8][rid#7f8e108d20a0][/_profiler/empty/search/results][4] Recipe: Invoking rule 7f8e0d40f5a0; [file "/etc/modsecurity/crs/crs-setup.conf"] [line "845"] [id "900990"].
However, it doesn't appear in the logs if specified with phase:4
(I couldn't find a line with 1000137
in it.)
I would expect this rule to block every page with <script>
inside it's HTML, but it doesn't, despite the <script>
tag 100% being in the response.
However, the installed rules from OWASP CRS set seem to work flawlessly.
My response body handling configuration:
SecResponseBodyAccess On
SecResponseBodyMimeType text/plain text/html text/xml
SecResponseBodyLimit 524288
SecResponseBodyLimitAction Reject
I tried restarting Apache by sudo service apache2 restart
several times.
I tried disabling all OWASP CRS rules and it still didn't help. Here's my debug log with phase 4: https://pastebin.com/8aXk8hL0 (it's pretty short)