0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WordPressのREST APIホワイトリスト運用設定メモ

0
Posted at

wp2shell(CVE-2026-63030およびCVE-2026-60137)脆弱性への対策としてインフラサイドで実施したREST APIのホワイトリスト運用設定のメモです。

概要

  • REST API全体をIPアドレスベースでアクセス制限する
  • どうしても公開したいAPIがある場合はWordPress設置先の.htaccessで制限緩和してもらう

検証環境

Apache + access_compat_module で、Order, Allow, Denyディレクティブを使った設定で検証、運用している環境です。
Requireディレクティブのサンプルも併記しますが、そちらは未検証です。

設定

ApacheによるREST APIへのアクセス制限

REST APIへのアクセスをローカルネット(192.168.0.xxx)に対してのみ許可する場合、confファイルに以下のような設定を記述します。

<If "%{REQUEST_URI} =~ m#(^|/)wp-json(?:/|$)# || %{QUERY_STRING} =~ m#(^|[&;])rest_route=#">
    ### mod_access_compat
    Order Deny,Allow
    Deny from all
    Allow from 192.168.0.

    ### Require directive 
    # Require ip 192.168.0.0/24
</If>

If文の%{REQUEST_URI} =~ ...条件では、'wp-json'を含むURLへのアクセス(サブディレクトリ運用を含む)を、%{QUERY_STRING} =~ ...条件では、クエリ文字列に'rest_route='を含むリクエスト(複数パラメータ対応)を判定しています。

.htaccessで特定のAPIだけ制限緩和する

例えば、'/some/api'というAPIのみグローバルに公開する場合、WordPressを設置しているディレクトリの.htaccess に以下のような設定を記述します。
(⚠️ 事前にApache側でAllowOverride ディレクティブの設定が必要です)

<If "%{REQUEST_URI} =~ m#(^|/)wp-json/some/api(?:/|$)# || %{QUERY_STRING} =~ m#(^|[&;])rest_route=(?:/|%2f)some(?:/|%2f)api(?:(?:/|%2f)|[&;]|$)#i">
    ### mod_access_compat
    Order Allow,Deny
    Allow from all
    
    ### Require directive 
    # Require all granted
</If> 

APIの個別パス指定で制限緩和を実現します(やろうとおもえば全APIの公開も出来てしまいますが、そこはWordPressサイト管理者の自己責任)。%{QUERY_STRING} =~ ...の条件式はURLエンコード('/' → '%2F')にも対応するためちょっと複雑になっています。そこまで拾うべきかは悩ましいですが。

動作検証

/wp-json

$ curl -ik -X POST -H 'Content-Type: application/json' --data '{
    "requests": [ { "method": "POST", "path": "/wp/v2/posts/999999" },
                  { "method": "POST", "path": "/wp/v2/posts/999998" } ]
  }'   'https://192.168.0.###/wp-json/batch/v1'

HTTP/1.1 403 Forbidden
(以下略)

?rest_route=

$ curl -ik -X POST -H 'Content-Type: application/json' --data '{
    "requests": [ { "method": "POST", "path": "/wp/v2/posts/999999" },
                  { "method": "POST", "path": "/wp/v2/posts/999998" } ]
  }'   'https://192.168.0.###/?rest_route=/batch/v1'

HTTP/1.1 403 Forbidden
(以下略)

以上です。

(皆さんよい夏休みを)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?