How to disable a specific mod_security rule in a specific directory?

a 夏天 提交于 2019-12-24 07:01:04

问题


I want to disable this rule:

[file "/usr/share/modsecurity-crs/activated_rules/modsecurity_crs_41_sql_injection_attacks.conf"] [line "159"] [id "981173"] [rev "2"] [msg "Restricted SQL Character Anomaly Detection Alert - Total # of special characters exceeded"] [data "Matched Data: - found within ARGS:customize_changeset_uuid: a507417f-75f3-434e-ac8c-90b21b3b164d"] [ver "OWASP_CRS/2.2.9"] [maturity "9"] [accuracy "8"] [tag "OWASP_CRS/WEB_ATTACK/SQL_INJECTION"]

For the directory

/var/www/romanpastu/wp-admin

Where should the exception go? In my .htaccess? or the vhost file?

Cuase nothing seems to be working.

Im using apache2

Ive tried adding the following in my virtualhost file. However, its still not working

<LocationMatch "/wp-admin/update.php">
    <IfModule security2_module>
        SecRuleRemoveById 981173
    </IfModule> </LocationMatch> <LocationMatch "/wp-admin/customize.php">
    <IfModule security2_module>
        SecRuleRemoveById 981173
    </IfModule> </LocationMatch>

回答1:


It should be added after the rule is defined in your config. So if you are defining your vhost (including removing above rule) and then load your ModSecurity rules later on in your config then that will not work - it needs to be the other way around.

Also, unless ModSecurity was compiled with the --enable-htaccess-config setting (which is not by default), then you cannot alter ModSecurity rules in htaccess files.

Additionally putting rules within LocationMatch can cause issues. And also wp-admin is exactly the sort of page you want to use ModSecuritg to protect against so carefully consider if you really want to turn off these rules. Please see also my answer to this question for some more information: Apache LocationMatch wildcard for ModSecurity on wordpress site.

So I would suggest using the following instead to only turn this rule off for this argument that's causing you issues:

 SecRuleUpdateTargetById 981173 !ARGS:'customize_changeset_uuid'

Note you may need to add similar exceptions if any other arguments cause problems.



来源:https://stackoverflow.com/questions/43572261/how-to-disable-a-specific-mod-security-rule-in-a-specific-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!