修复wordpress安全漏洞

1. 问题描述:

用wordpress建了一个网站,但是学校反映说存在安全漏洞,通过接口https://xxx.xxx.edu.cn/?rest_route=/wp/v2/users/可以访问到一些内容,希望可以关闭这个接口。

2. 解决办法

一共两步

(1)在functions.php添加内容:

(这个php的文件路径一般在你安装wprdpress的路径的themes下,比如我的在:

/var/www/html/wp-content/themes/astra/functions.php)

html 复制代码
add_filter( 'rest_endpoints', function( $endpoints ){
    if ( isset( $endpoints['/wp/v2/users'] ) ) {
        unset( $endpoints['/wp/v2/users'] );
    }
    return $endpoints;
});

(2) 在.htaccess文件中添加:

(这个文件在你安装的wordpress路径下,比如我的在/var/www/html/.htaccess)

(因为我安装wp的时候是基于apache去配置的,修改的是.htaccess这个文件,如果你是基于Nginx的话,需要修改的是Nginx对应的文件)

html 复制代码
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/wp-json/wp/v2/users/?$
RewriteRule ^.* - [R=403,L]
</IfModule>

3. 结果

修改后在这个接口下就返回不了啥有效信息了

  1. 其他

不知道截图软件咋了,打字时候"c"打不出来,所以文中图片标注有一些出入,比如"function"->"funtion, htaccess->htaess

相关推荐
Escalating_xu9 小时前
【MySQL】视图特性:从创建与基表联动,到更新限制、权限与 SQL 实战
android·sql·mysql
shih94518 小时前
16G 内存不够用之后,我把旧安卓手机接进了 k3s 集群
android·k3s
阿杰m19 小时前
Android源码第三十章:Android Automotive、TV 与桌面模式
android
意念回复1 天前
Transformer 系列(五):从 Block 到模型——三大架构、因果掩码与自回归生成
android·回归·transformer
松仔log1 天前
Kotlin中级——KMP
android·开发语言·kotlin
GY-931 天前
【Android】SQL数据库
android
GY-931 天前
【Android】适配不同的屏幕尺寸
android
Chenpip11 天前
安卓 14/15 上装不上:四层原因与三行检查
android·app分发·应用分发·海哈游分发·内测
TT哇1 天前
【Android 之旅】Android 通俗易懂记
android·gitee
雨白1 天前
工厂设计模式实战:从简单工厂到抽象工厂的演进之路
android