为特定目录禁用 modsecurity

dra*_*ank 12 httpd centos mod-security apache-2.2

如何仅针对特定目录禁用 modsecurity。我在 phpMyAdmin 中遇到错误,这是由基于规则的 modsecurity 跳闸引起的。我设置了以下文件:

# /etc/httpd/modsecurity.d/modsecurity_crs_15_customrules.conf
<LocationMatch "^/phpMA/">
    SecRuleEngine Off
</LocationMatch>

# /etc/httpd/modsecurity.d/modsecurity_crs_60.custom.conf
<LocationMatch '^/phpMA/*'>
    SecRuleRemoveById 950004
    SecRuleRemoveById 950005
    SecRuleRemoveById 950006
    SecRuleRemoveById 960010
    SecRuleRemoveById 960012
</LocationMatch>
Run Code Online (Sandbox Code Playgroud)

从我可以找到的第一个文件应该禁用它,但它仍然跳闸,所以我尝试添加它跳闸到 60 文件的规则 ID,但它仍然抱怨。

我在 CentOS 5.3 上运行以下软件包:

  • mod_security-2.5.0-jason.2
  • httpd-2.2.8-jason.3
  • mod-php5-apache2-zend-ce-5.2.10-65

hda*_*iel 19

SecRuleEngine Off 必须工作。您是否尝试将 SecRuleEngine 放在目录中:

<Directory /var/www/site/phpMA>
SecRuleEngine Off
</Directory>
Run Code Online (Sandbox Code Playgroud)

而不是 LocationMatch ?


Sim*_*ast 5

某些服务器和网络主机上,可以通过 禁用 ModSecurity .htaccess,但通过此方法您只能打开或关闭它,通常不能禁用单个规则。

\n

因此,最好将其限制为特定 URL,而不是让整个站点不受保护。您可以在下面的语句中的正则表达式中指定它们<If>...

\n
### DISABLE mod_security firewall\n### Some rules are currently too strict and are blocking legitimate users\n### We only disable it for URLs that contain the regex below\n### The regex below should be placed between "m#" and "#" \n### (this syntax is required when the string contains forward slashes)\n<IfModule mod_security.c>\n  <If "%{REQUEST_URI} =~ m#/admin/#">\n    SecFilterEngine Off\n    SecFilterScanPOST Off\n  </If>\n</IfModule>\n
Run Code Online (Sandbox Code Playgroud)\n