在WordPress编辑器中进行编辑后,几分钟后,我的IP将被mod_security
自动阻止,并将其放入防火墙拒绝访问列表中,并且日志显示安全问题“ 最近300秒内为5 ”。
lfd: (mod_security) mod_security triggered by xx.xx.xx.xx (MY/Malaysia/-): 5 in the last 300 secs
为了快速修复它,我必须重新启动调制解调器或获取新IP以通过SSH或WHM访问我的服务器,然后手动删除被阻止的IP。 这是我的环境:
- WordPress 3.4.2
- 经典Apache + ModSecurity + CSF / LFD
经过多次尝试和错误,我发现这可能是由WordPress的“自动保存”和修订后的功能引起的。 在编辑帖子时,WordPress将在定义的时间间隔内自动保存“草稿”或“帖子修订”,而且经常会轻易触发 mod_security
规则。
这是两个解决方案:
1.将WordPress动作列入白名单
这是我的服务器支持者建议的,在mod_security
中将一些常见的WordPress操作列入白名单。 编辑whitelist.conf
,并将以下规则放入其中。
/usr/local/apache/conf/modsec2/whitelist.conf
<LocationMatch "/wp-admin/page.php">
SecRuleRemoveById 300013 300014 300015 300016 300017
</LocationMatch>
<LocationMatch "/wp-admin/post.php">
SecRuleRemoveById 300013 300014 300015 300016 300017
</LocationMatch>
<LocationMatch "/wp-admin/admin-ajax.php">
SecRuleRemoveById 300013 300014 300015 300016 300017
</LocationMatch>
SecRule REQUEST_URI "/wp-admin/async-upload.php" phase:1,nolog,allow,ctl:ruleEngine=Off
SecRule REQUEST_URI "/wp-admin/async-upload.php" phase:2,nolog,allow,ctl:ruleEngine=Off
2.禁用发布修订
禁用WordPress发布修订功能,或增加其自动保存间隔。 编辑wp-config.php
,添加以下代码:
define('AUTOSAVE_INTERVAL', 300 ); // seconds, 5 mins
define('WP_POST_REVISIONS', false );
这是我完整的wp-config.php
示例
wp-config.php
<?php
/** Enable W3 Total Cache */
define('WP_CACHE', true); // Added by W3 Total Cache
define('AUTOSAVE_INTERVAL', 300 ); // seconds, 5 mins
define('WP_POST_REVISIONS', false );
// ** MySQL settings ** //Added by WP-Cache Manager
define('DB_NAME', 'removed-for-security'); // The name of the database
define('DB_USER', 'removed-for-security'); // Your MySQL username
define('DB_PASSWORD', 'removed-for-security'); // ...and password
define('DB_HOST', 'localhost'); // 99% chance you won't need to change this value
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
define('AUTH_KEY', 'removed-for-security');
define('SECURE_AUTH_KEY', 'removed-for-security');
define('LOGGED_IN_KEY', 'removed-for-security');
define('NONCE_KEY', 'removed-for-security');
$table_prefix = 'abc_';
define ('WPLANG', '');
@ini_set('log_errors','On');
@ini_set('display_errors','Off');
@ini_set('error_log','/home/username/www/php-errors.log');
/* That's all, stop editing! Happy blogging. */
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
require_once(ABSPATH . 'wp-settings.php');
?>
参考文献
- 更新帖子后显示WordPress 404
- WordPress自动保存
- ConfigServer安全性和防火墙
- 国防部安全
- 更改WordPress自动保存频率和发布修订
- WordPress:禁用发布修订/关闭修订
翻译自: https://mkyong.com/blog/mod_security-blocking-my-ip-when-editing-post-in-wordpress/