This is an automated email from the ASF dual-hosted git repository.

nic-6443 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 0cf8b6ace fix(plugin): ignore plugin_metadata of disabled or unknown 
plugins (#13514)
0cf8b6ace is described below

commit 0cf8b6acefdd7254dfd4a48059fa4a25887c3e6c
Author: Nic <[email protected]>
AuthorDate: Fri Jun 12 10:51:46 2026 +0800

    fix(plugin): ignore plugin_metadata of disabled or unknown plugins (#13514)
---
 apisix/plugin.lua                      |  20 +++++--
 t/config-center-yaml/plugin-metadata.t | 102 +++++++++++++++++++++++++++++++++
 2 files changed, 118 insertions(+), 4 deletions(-)

diff --git a/apisix/plugin.lua b/apisix/plugin.lua
index 2e664e64f..0a30410f7 100644
--- a/apisix/plugin.lua
+++ b/apisix/plugin.lua
@@ -970,15 +970,20 @@ end
 
 
 
-local function check_single_plugin_schema(name, plugin_conf, schema_type, 
skip_disabled_plugin)
+local function check_single_plugin_schema(name, plugin_conf, schema_type, 
skip_disabled_plugin,
+                                          ignore_disabled_plugin)
     if type(plugin_conf) ~= "table" then
         return false, "invalid plugin conf " ..
             core.json.encode(plugin_conf, true) ..
-            " for plugin [" .. name .. "]"
+            " for plugin [" .. tostring(name) .. "]"
     end
 
     local plugin_obj = local_plugins_hash[name]
     if not plugin_obj then
+        if ignore_disabled_plugin then
+            return true
+        end
+
         if skip_disabled_plugin then
             core.log.warn("skipping check schema for disabled or unknown 
plugin [",
                                     name, "]. Enable the plugin or modify 
configuration")
@@ -1183,9 +1188,16 @@ _M.encrypt_conf = encrypt_conf
 
 
 check_plugin_metadata = function(item)
+    -- A plugin_metadata entry takes no effect until its plugin is enabled,
+    -- so entries of disabled or unknown plugins are ignored silently. This
+    -- also covers the entries of the other subsystem's plugins: the
+    -- plugin_metadata directory is watched by both the http and the stream
+    -- subsystems, while each of them only loads its own plugins.
     local ok, err = check_single_plugin_schema(item.id, item,
-                                               core.schema.TYPE_METADATA, true)
-    if ok and enable_gde() then
+                                               core.schema.TYPE_METADATA, 
false, true)
+    -- the schema of an unloaded plugin is unavailable, so decrypting its
+    -- metadata would only produce a "failed to get schema" warning
+    if ok and enable_gde() and local_plugins_hash[item.id] then
         decrypt_conf(item.id, item, core.schema.TYPE_METADATA)
     end
 
diff --git a/t/config-center-yaml/plugin-metadata.t 
b/t/config-center-yaml/plugin-metadata.t
index 34c6949b8..9dbe81c5b 100644
--- a/t/config-center-yaml/plugin-metadata.t
+++ b/t/config-center-yaml/plugin-metadata.t
@@ -87,3 +87,105 @@ plugin_metadata:
 GET /hello
 --- error_log
 failed to check item data of [plugin_metadata]
+
+
+
+=== TEST 3: metadata of plugins from the other subsystem should be skipped 
silently
+--- yaml_config
+apisix:
+    node_listen: 1984
+    proxy_mode: http&stream
+    stream_proxy:
+        tcp:
+            - 9100
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+--- stream_enable
+--- apisix_yaml
+upstreams:
+  - id: 1
+    nodes:
+      "127.0.0.1:1980": 1
+    type: roundrobin
+routes:
+  -
+    uri: /hello
+    upstream_id: 1
+    plugins:
+        cors:
+            allow_origins_by_metadata:
+                - local
+plugin_metadata:
+  - id: cors
+    allow_origins:
+        local: "http://example.com";
+  - id: mqtt-proxy
+    log_format:
+        host: "$host"
+#END
+--- request
+GET /hello
+--- response_body
+hello world
+--- no_error_log
+disabled or unknown plugin
+
+
+
+=== TEST 4: metadata of a disabled or unknown plugin is ignored silently
+--- extra_yaml_config
+apisix:
+    data_encryption:
+        enable_encrypt_fields: true
+        keyring:
+            - edd1c9f0985e76a2
+--- apisix_yaml
+upstreams:
+  - id: 1
+    nodes:
+      "127.0.0.1:1980": 1
+    type: roundrobin
+routes:
+  -
+    uri: /hello
+    upstream_id: 1
+plugin_metadata:
+  - id: plugin-not-exist
+    log_format:
+        host: "$host"
+#END
+--- request
+GET /hello
+--- response_body
+hello world
+--- no_error_log
+disabled or unknown plugin
+failed to check item data of [plugin_metadata]
+failed to get schema
+
+
+
+=== TEST 5: metadata entry without id is ignored silently
+--- apisix_yaml
+upstreams:
+  - id: 1
+    nodes:
+      "127.0.0.1:1980": 1
+    type: roundrobin
+routes:
+  -
+    uri: /hello
+    upstream_id: 1
+plugin_metadata:
+  - log_format:
+        host: "$host"
+#END
+--- request
+GET /hello
+--- response_body
+hello world
+--- no_error_log
+disabled or unknown plugin
+failed to check item data of [plugin_metadata]

Reply via email to