月度归档: 2022 年 6 月

  • WordPress禁用指定endpoints,防止用户信息泄露

    WordPress 在4.7.0版本之后将REST API插件集成到默认功能之中。REST API为WordPress的使用者提供了一个方便快捷的管理接口。在WordPress 4.7.0版本中,存在着一个越权漏洞,成功的利用这个漏洞,可以绕过管理员权限查看WordPress上所有发布过文章的用户信息列表。

    虽然现在用的不是4.7.0这个版本,但是为了确保安全,最好还是把这两个rest api接口禁用掉吧。

    禁用代码如下:

    // language: php
    // 禁用用户端点,同时确保其他 REST API 功能正常
    add_filter('rest_endpoints', function ($endpoints) {
        if (isset($endpoints['/wp/v2/users'])) {
            unset($endpoints['/wp/v2/users']);
        }
        if (isset($endpoints['/wp/v2/users/(?P<id>[\d]+)'])) {
            unset($endpoints['/wp/v2/users/(?P<id>[\d]+)']);
        }
        return $endpoints;
    });