毋庸置疑 WordPress 算是当前比较好用的 PHP 程序,基本上个人博客、企业网站,小型商务网站都可以使用到。而且 WordPress 官方的更新、第三方的插件主题丰富,让这个程序变得越来越丰富多样,但是随着不断的升级功能,也会增加程序的负担和不安全因素。
比如 WordPress 从 4.4 版本开始新增的 JSON REST API 功能,通过这个 REST API 可以很轻松的获取网站的数据,可应用于其他网站、手机 APP 或小程序等;但对于一般的网站是没有需要的,反而会拖累网站的速度,而且 REST API 采用 GET 请求方式,这就为 DDOS 攻击提供了一个新的攻击途径,所以我们应尽可能的禁止掉这些不必要的功能需求,并且去掉 head 里面输出 wp-json 链接。在此也说下查看 WP JSON REST API 是否开启的方法:http://域名/wp-json/
,若输出数据则是开启状态。
因此如果我们想兼容所有版本的 Wordpress,我们可以直接使用插件Disable REST API或Disable WP REST API来完全禁用 REST API;但我更倾向纯代码的方法,在这里就介绍下代码版兼容所有 Wordpress 版本的完全禁用 REST API 或者说移除 head 里面 wp-json 链接的方法。
对于 WP 4.7 以上版本,通过rest_api_init
这个钩子来禁用 REST API 的方法,大家也可以尝试并改造下。
/** * WordPress完全禁用REST API(最新版) */ /*禁用未登录的用户*/ add_filter( 'rest_api_init', 'lxtx_rest_only_for_authorized_users', 99 ); function lxtx_rest_only_for_authorized_users($wp_rest_server){ if ( !is_user_logged_in() ) { wp_die('非法操作!'); } }
1 条评论
{!{data:image/webp;base64,UklGRmwcAABXRUJQVlA4WAoAAAAwAAAAxAMAKwEASUNDUBgCAAAAAAIYAAAAAAQwAABtbnRyUkdCIFhZWiAAAAAAAAAAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlkZXNjAAAA8AAAAHRyWFlaAAABZAAAABRnWFlaAAABeAAAABRiWFlaAAABjAAAABRyVFJDAAABoAAAAChnVFJDAAABoAAAAChiVFJDA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