我在我的 apache2 生产服务器上托管了一个 nextcloud 应用程序,我在该服务器上使用 modsecurity 进行加固。
由于 modsecurity 会将 Nextcloud 生成的许多请求检测为误报,因此我想通过“tx.crs_exclusions_nextcloud=1”启用特殊的 modsecurity nextcloud 排除项。由于我在此服务器上托管多个 vHosts/子域,并且 nextcloud 有自己的一个(以及它不是为每个子域全局执行此类排除的选项),我想通过 Apache VirtualHost 配置目录启用此排除:
<VirtualHost _default_:443>
ServerName nextcloud.mydomain.tld
...
SecAction "id:x,pass,log,setvar:tx.crs_exclusions_nextcloud=1" #also tried ALL possible combinations of variables (id, log, nolog, pass, ...) etc, please don't assume the issue being here as long as you don't are 100% sure.
...
</VirtualHost>
这不起作用。我完全不知道为什么。文档说这个命令在 VirtualHost 部分是可用的,我检查了包含的配置文件的顺序。
命令:
- Mod本身正在加载
- /etc/apache2/mods-enabled/security2.conf
- /etc/modsecurity/000_modsecurity.conf
- /etc/modsecurity/001_crs-setup.conf
- /etc/modsecurity/rules/*.conf | OWASP ModSecurity CRS v3.3.0 <--- 规则定义
- /etc/modsecurity/002_crs-exclusions.conf <--- 当前修补程序,见下文
- 站点配置 <--- <VirtualHost>
由于SecAction在 VirtualHost 中不起作用,并且 modsecurity 仍将许多 nextcloud 请求检测为误报,我目前使用最后一个文件 002_crs-exclusions.conf 来激活 nextcloud 排除项:
SecRule REQUEST_HEADERS:Host ^nextcloud.mydomain.tld$ "id:900130,phase:1,nolog,pass,t:none,setvar:tx.crs_exclusions_nextcloud=1"
哪个有效。位我对这个解决方案不满意 - 我想通过 VirtualHost 指令使用它,因为这应该可以工作。
第二期
/remote.php/dav/calendars/<user>/personal/<uuid>.ics如果用户尝试更新日历条目,Modsecurity 会阻止请求 URI 。这是因为这个请求有 HeaderContent-Type: application/xml但没有真正的 xml 内容,这导致 modsecurity 出现 libxml2 解析错误。所以我想通过<Location> 指令为 URI排除规则# 200000(此规则定义 Header Content-Type: application/xml-requests 应该通过 modsecurity 的 xml-parser) :/remote.php/dav/calendars/.*SecRuleRemoveById
<Location ~ "/remote.php/dav/calendars/.*">
Header set LocDebug "works" #to check if <Location> is applied correctly
SecRuleRemoveById 200000
</Location>
结果:
到达这些 URI 之一的每个请求(加载日历等)都包含标头 LocDebug,表明 <Location ...> 中的规则已成功应用 - 但如果用户尝试更新日历条目(使用格式错误的 xml 的请求),请求仍然失败,HTTP 500 和 modsecurity 报告解析错误 - 此请求没有 LocDebug 标头,导致我假设应用的这些操作和命令的顺序存在一些问题当请求被实际解析时。
我也尝试过SecRuleRemoveById全局设置,但是这个完全不起作用。
我尝试了一切,从字面上看,一切,如上面所述,订单应该没问题。
有谁知道我可能做错了什么或问题可能出在哪里?我一无所知。
技术信息:
- 操作系统:Debian 10 Buster - 所有软件包最新版本。
- 阿帕奇:apache2.4.38-3+deb10u4
- ModSecurity:libapache2-mod-security2 v2.9.3-1