在WordPress中编辑帖子时,mod_security阻止了我的IP

wordpress-firewall image

在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。 这是我的环境:

  1. WordPress 3.4.2
  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');
?>

参考文献

  1. 更新帖子后显示WordPress 404
  2. WordPress自动保存
  3. ConfigServer安全性和防火墙
  4. 国防部安全
  5. 更改WordPress自动保存频率和发布修订
  6. WordPress:禁用发布修订/关闭修订

翻译自: https://mkyong.com/blog/mod_security-blocking-my-ip-when-editing-post-in-wordpress/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值