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

AlinsRan 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 309cd29475 fix: avoid logging configuration values during validation 
and plugin execution (#14157)
309cd29475 is described below

commit 309cd294756003ed3c47f0c26193078b44b3a668
Author: AlinsRan <[email protected]>
AuthorDate: Wed Nov 18 17:53:46 2026 +0800

    fix: avoid logging configuration values during validation and plugin 
execution (#14157)
---
 apisix/core/config_etcd.lua            |  12 +-
 apisix/http/route.lua                  |   3 +-
 apisix/http/service.lua                |   2 +-
 apisix/init.lua                        |   7 +-
 apisix/plugin.lua                      |  25 +--
 apisix/plugins/batch-requests.lua      |   2 +-
 apisix/plugins/datadog.lua             |   2 +-
 apisix/plugins/error-page.lua          |   1 -
 apisix/plugins/example-plugin.lua      |  18 +-
 apisix/plugins/fault-injection.lua     |   2 +-
 apisix/plugins/graphql-proxy-cache.lua |   6 +-
 apisix/plugins/grpc-transcode.lua      |   2 +-
 apisix/plugins/limit-count/init.lua    |   7 +-
 apisix/plugins/loggly.lua              |   2 +-
 apisix/plugins/opentelemetry.lua       |   1 -
 apisix/plugins/proxy-cache/init.lua    |   6 +-
 apisix/plugins/proxy-mirror.lua        |   2 +-
 apisix/plugins/redirect.lua            |   2 +-
 apisix/plugins/traffic-split.lua       |   1 -
 apisix/stream/plugins/mqtt-proxy.lua   |   2 +-
 apisix/utils/log-util.lua              |   2 +-
 t/node/data_encrypt_invalid_conf.t     | 183 +++++++++++++++
 t/node/merge-route.t                   |   4 +-
 t/node/plugin-conf-log-secret.t        | 399 +++++++++++++++++++++++++++++++++
 t/plugin/basic-auth.t                  |   2 +-
 t/plugin/ldap-auth.t                   |   2 +-
 t/plugin/limit-count-redis2.t          |   6 +-
 t/plugin/request-id3.t                 |   4 +-
 t/plugin/traffic-split5.t              |   2 +
 t/script/script.t                      |   2 +-
 30 files changed, 642 insertions(+), 69 deletions(-)

diff --git a/apisix/core/config_etcd.lua b/apisix/core/config_etcd.lua
index eebc726511..29a6e32945 100644
--- a/apisix/core/config_etcd.lua
+++ b/apisix/core/config_etcd.lua
@@ -561,7 +561,7 @@ local function load_full_data(self, dir_res, headers, 
prev_values, prev_values_h
             data_valid, err = check_schema(self.item_schema, item.value)
             if not data_valid then
                 log.error("failed to check item data of [", self.key,
-                          "] err:", err, " ,val: ", json.encode(item.value))
+                          "] err:", err, ", key: ", item.key)
             end
         end
 
@@ -569,7 +569,7 @@ local function load_full_data(self, dir_res, headers, 
prev_values, prev_values_h
             data_valid, err = self.checker(item.value, item.key)
             if not data_valid then
                 log.error("failed to check item data of [", self.key,
-                          "] err:", err, " ,val: ", 
json.delay_encode(item.value))
+                          "] err:", err, ", key: ", item.key)
             end
         end
 
@@ -640,7 +640,7 @@ local function load_full_data(self, dir_res, headers, 
prev_values, prev_values_h
                 data_valid, err = check_schema(self.item_schema, item.value)
                 if not data_valid then
                     log.error("failed to check item data of [", self.key,
-                              "] err:", err, " ,val: ", 
json.encode(item.value))
+                              "] err:", err, ", key: ", item.key)
                 end
             end
 
@@ -650,7 +650,7 @@ local function load_full_data(self, dir_res, headers, 
prev_values, prev_values_h
                 data_valid, err = self.checker(item.value, item.key)
                 if not data_valid then
                     log.error("failed to check item data of [", self.key,
-                              "] err:", err, " ,val: ", 
json.delay_encode(item.value))
+                              "] err:", err, ", key: ", item.key)
                 end
             end
 
@@ -797,7 +797,7 @@ local function sync_data(self)
             data_valid, err = check_schema(self.item_schema, res.value)
             if not data_valid then
                 log.error("failed to check item data of [", self.key,
-                          "] err:", err, " ,val: ", json.encode(res.value))
+                          "] err:", err, ", key: ", res.key)
             end
         end
 
@@ -805,7 +805,7 @@ local function sync_data(self)
             data_valid, err = self.checker(res.value, res.key)
             if not data_valid then
                 log.error("failed to check item data of [", self.key,
-                          "] err:", err, " ,val: ", 
json.delay_encode(res.value))
+                          "] err:", err, ", key: ", res.key)
             end
         end
 
diff --git a/apisix/http/route.lua b/apisix/http/route.lua
index dbf11abf5e..4a6900c142 100644
--- a/apisix/http/route.lua
+++ b/apisix/http/route.lua
@@ -70,8 +70,7 @@ function _M.create_radixtree_uri_router(routes, uri_routes, 
with_parameter)
                 end
             end
 
-            core.log.info("insert uri route: ",
-                          core.json.delay_encode(route.value, true))
+            core.log.info("insert uri route: ", route.value.id)
             core.table.insert(uri_routes, {
                 paths = route.value.uris or route.value.uri,
                 methods = route.value.methods,
diff --git a/apisix/http/service.lua b/apisix/http/service.lua
index 5ed04a2781..c03b6d3ab2 100644
--- a/apisix/http/service.lua
+++ b/apisix/http/service.lua
@@ -66,7 +66,7 @@ local function filter(service)
 
     apisix_upstream.filter_upstream(service.value.upstream, service)
 
-    core.log.info("filter service: ", core.json.delay_encode(service, true))
+    core.log.info("filter service: ", service.value.id)
 end
 
 
diff --git a/apisix/init.lua b/apisix/init.lua
index 451a95108f..a2e98cfe5c 100644
--- a/apisix/init.lua
+++ b/apisix/init.lua
@@ -1011,8 +1011,7 @@ function _M.http_access_phase()
     end
     match_span:finish(ngx_ctx)
 
-    core.log.info("matched route: ",
-                  core.json.delay_encode(api_ctx.matched_route, true))
+    core.log.info("matched route: ", api_ctx.matched_route.value.id)
 
     local enable_websocket = route.value.enable_websocket
 
@@ -1882,14 +1881,12 @@ function _M.stream_preread_phase(tls_passthrough, 
behind_mixed_hop)
         return ngx_exit(1)
     end
 
-    core.log.info("matched route: ",
-                  core.json.delay_encode(api_ctx.matched_route, true))
-
     local matched_route = api_ctx.matched_route
     if not matched_route then
         return ngx_exit(1)
     end
 
+    core.log.info("matched route: ", matched_route.value.id)
 
     local up_id = matched_route.value.upstream_id
     if up_id then
diff --git a/apisix/plugin.lua b/apisix/plugin.lua
index 2cc1064e04..d2188aef17 100644
--- a/apisix/plugin.lua
+++ b/apisix/plugin.lua
@@ -761,8 +761,9 @@ end
 
 
 function _M.merge_service_route(service_conf, route_conf)
-    core.log.info("service conf: ", core.json.delay_encode(service_conf, true))
-    core.log.info("  route conf: ", core.json.delay_encode(route_conf, true))
+    -- the confs hold decrypted values, so log their ids only
+    core.log.info("merge service [", service_conf.value.id, "] into route [",
+                  route_conf.value.id, "]")
 
     local route_service_key = route_conf.value.id .. "#"
         .. route_conf.modifiedIndex .. "#" .. service_conf.modifiedIndex
@@ -803,8 +804,8 @@ end
 
 
 function _M.merge_service_stream_route(service_conf, route_conf)
-    core.log.info("service conf: ", core.json.delay_encode(service_conf, true))
-    core.log.info("  stream route conf: ", core.json.delay_encode(route_conf, 
true))
+    core.log.info("merge service [", service_conf.value.id, "] into stream 
route [",
+                  route_conf.value.id, "]")
 
     local version = route_conf.modifiedIndex .. "#" .. 
service_conf.modifiedIndex
     local route_service_key = route_conf.value.id .. "#"
@@ -869,8 +870,9 @@ end
 
 
 function _M.merge_consumer_route(route_conf, consumer_conf, 
consumer_group_conf, api_ctx)
-    core.log.info("route conf: ", core.json.delay_encode(route_conf))
-    core.log.info("consumer group conf: ", 
core.json.delay_encode(consumer_group_conf))
+    core.log.info("merge consumer [", consumer_conf.id, "] and consumer group 
[",
+                  consumer_group_conf and consumer_group_conf.value.id, "] 
into route [",
+                  route_conf.value.id, "]")
 
     local flag = route_conf.value.id .. "#" .. route_conf.modifiedIndex
                  .. "#" .. consumer_conf.id .. "#" .. 
consumer_conf.modifiedIndex
@@ -1015,7 +1017,7 @@ function _M.conf_version(conf)
             exception = encode_json_null,
         })
         conf._version = tostring(crc32(data))
-        core.log.info("init plugin-level conf version: ", conf._version, ", 
from ", data)
+        core.log.info("init plugin-level conf version: ", conf._version)
     end
 
     return conf._version
@@ -1026,8 +1028,7 @@ end
 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) ..
+        return false, "invalid plugin conf type " .. type(plugin_conf) ..
             " for plugin [" .. tostring(name) .. "]"
     end
 
@@ -1349,11 +1350,9 @@ _M.check_schema = check_schema
 
 local function stream_check_schema(plugins_conf, schema_type, 
skip_disabled_plugin)
     for name, plugin_conf in pairs(plugins_conf) do
-        core.log.info("check stream plugin schema, name: ", name,
-                      ": ", core.json.delay_encode(plugin_conf, true))
+        core.log.info("check stream plugin schema, name: ", name)
         if type(plugin_conf) ~= "table" then
-            return false, "invalid plugin conf " ..
-                core.json.encode(plugin_conf, true) ..
+            return false, "invalid plugin conf type " .. type(plugin_conf) ..
                 " for plugin [" .. name .. "]"
         end
 
diff --git a/apisix/plugins/batch-requests.lua 
b/apisix/plugins/batch-requests.lua
index d8faa288b6..e5db274f31 100644
--- a/apisix/plugins/batch-requests.lua
+++ b/apisix/plugins/batch-requests.lua
@@ -303,7 +303,7 @@ end
 
 local function batch_requests(ctx)
     local metadata = plugin.plugin_metadata(plugin_name)
-    core.log.info("metadata: ", core.json.delay_encode(metadata))
+    core.log.info("metadata of plugin ", plugin_name, " found: ", metadata ~= 
nil)
 
     local max_body_size
     local max_pipeline_items
diff --git a/apisix/plugins/datadog.lua b/apisix/plugins/datadog.lua
index 66e5e8ae18..4d72a2aef5 100644
--- a/apisix/plugins/datadog.lua
+++ b/apisix/plugins/datadog.lua
@@ -179,7 +179,7 @@ end
 local function push_metrics(entries)
     -- Fetching metadata details
     local metadata = plugin.plugin_metadata(plugin_name)
-    core.log.info("metadata: ", core.json.delay_encode(metadata))
+    core.log.info("metadata of plugin ", plugin_name, " found: ", metadata ~= 
nil)
 
     if not metadata then
         core.log.info("received nil metadata: using metadata defaults: ",
diff --git a/apisix/plugins/error-page.lua b/apisix/plugins/error-page.lua
index 89c880bfbf..a96fac5988 100644
--- a/apisix/plugins/error-page.lua
+++ b/apisix/plugins/error-page.lua
@@ -103,7 +103,6 @@ local function get_metadata(ctx)
         core.log.info("failed to read metadata for ", plugin_name)
         return nil
     end
-    core.log.debug(plugin_name, " metadata: ", 
core.json.delay_encode(metadata))
     metadata = metadata.value
     if not metadata.enable then
         return nil
diff --git a/apisix/plugins/example-plugin.lua 
b/apisix/plugins/example-plugin.lua
index e76ce72e9e..25ed2c78af 100644
--- a/apisix/plugins/example-plugin.lua
+++ b/apisix/plugins/example-plugin.lua
@@ -74,7 +74,7 @@ end
 
 
 function _M.rewrite(conf, ctx)
-    core.log.warn("plugin rewrite phase, conf: ", core.json.encode(conf))
+    core.log.warn("plugin rewrite phase")
     core.log.warn("conf_type: ", ctx.conf_type)
     core.log.warn("conf_id: ", ctx.conf_id)
     core.log.warn("conf_version: ", ctx.conf_version)
@@ -82,7 +82,7 @@ end
 
 
 function _M.access(conf, ctx)
-    core.log.warn("plugin access phase, conf: ", core.json.encode(conf))
+    core.log.warn("plugin access phase")
     -- return 200, {message = "hit example plugin"}
 
     if not conf.ip then
@@ -108,28 +108,26 @@ function _M.access(conf, ctx)
 end
 
 function _M.header_filter(conf, ctx)
-    core.log.warn("plugin header_filter phase, conf: ", core.json.encode(conf))
+    core.log.warn("plugin header_filter phase")
 end
 
 
 function _M.body_filter(conf, ctx)
-    core.log.warn("plugin body_filter phase, eof: ", ngx.arg[2],
-                  ", conf: ", core.json.encode(conf))
+    core.log.warn("plugin body_filter phase, eof: ", ngx.arg[2])
 end
 
 
 function _M.delayed_body_filter(conf, ctx)
-    core.log.warn("plugin delayed_body_filter phase, eof: ", ngx.arg[2],
-                  ", conf: ", core.json.encode(conf))
+    core.log.warn("plugin delayed_body_filter phase, eof: ", ngx.arg[2])
 end
 
 function _M.log(conf, ctx)
-    core.log.warn("plugin log phase, conf: ", core.json.encode(conf))
+    core.log.warn("plugin log phase")
 end
 
 
 function _M.ws_handshake(conf, ctx)
-    core.log.warn("plugin ws_handshake phase, conf: ", core.json.encode(conf))
+    core.log.warn("plugin ws_handshake phase")
 end
 
 
@@ -152,7 +150,7 @@ end
 
 
 function _M.ws_close(conf, ctx)
-    core.log.warn("plugin ws_close phase, conf: ", core.json.encode(conf))
+    core.log.warn("plugin ws_close phase")
 end
 
 
diff --git a/apisix/plugins/fault-injection.lua 
b/apisix/plugins/fault-injection.lua
index 34ca05e817..834cb4c47c 100644
--- a/apisix/plugins/fault-injection.lua
+++ b/apisix/plugins/fault-injection.lua
@@ -140,7 +140,7 @@ end
 
 
 function _M.rewrite(conf, ctx)
-    core.log.info("plugin rewrite phase, conf: ", core.json.delay_encode(conf))
+    core.log.info("plugin rewrite phase")
 
     local abort_vars = true
     if conf.abort and conf.abort.vars then
diff --git a/apisix/plugins/graphql-proxy-cache.lua 
b/apisix/plugins/graphql-proxy-cache.lua
index 3fb38311d6..874e724f64 100644
--- a/apisix/plugins/graphql-proxy-cache.lua
+++ b/apisix/plugins/graphql-proxy-cache.lua
@@ -289,8 +289,7 @@ function _M.header_filter(conf, ctx)
     end
 
     local cache_conf = graphql_cache_conf(ctx, conf)
-    core.log.debug("graphql-proxy-cache plugin header filter phase, conf: ",
-                    core.json.delay_encode(cache_conf))
+    core.log.debug("graphql-proxy-cache plugin header filter phase")
 
     local handler
     if ctx.graphql_cache_conf.cache_strategy == STRATEGY_MEMORY then
@@ -309,8 +308,7 @@ function _M.body_filter(conf, ctx)
     end
 
     local cache_conf = graphql_cache_conf(ctx, conf)
-    core.log.debug("graphql-proxy-cache plugin body filter phase, conf: ",
-                        core.json.delay_encode(cache_conf))
+    core.log.debug("graphql-proxy-cache plugin body filter phase")
 
     if ctx.graphql_cache_conf.cache_strategy == STRATEGY_MEMORY then
         memory_handler.body_filter(cache_conf, ctx)
diff --git a/apisix/plugins/grpc-transcode.lua 
b/apisix/plugins/grpc-transcode.lua
index 3b5d58046e..de26a9de4b 100644
--- a/apisix/plugins/grpc-transcode.lua
+++ b/apisix/plugins/grpc-transcode.lua
@@ -145,7 +145,7 @@ end
 
 
 function _M.access(conf, ctx)
-    core.log.info("conf: ", core.json.delay_encode(conf))
+    core.log.info("proto_id: ", conf.proto_id)
 
     local proto_id = conf.proto_id
     if not proto_id then
diff --git a/apisix/plugins/limit-count/init.lua 
b/apisix/plugins/limit-count/init.lua
index 111ccc77fa..7f0186ad4d 100644
--- a/apisix/plugins/limit-count/init.lua
+++ b/apisix/plugins/limit-count/init.lua
@@ -291,10 +291,8 @@ function _M.check_schema(conf, schema_type)
 
         for _, field in ipairs(fields) do
             if not core.table.deep_eq(prev_conf[field], conf[field]) then
-                core.log.error("previous limit-count group ", prev_conf.group,
-                            " conf: ", core.json.encode(prev_conf))
-                core.log.error("current limit-count group ", conf.group,
-                            " conf: ", core.json.encode(conf))
+                core.log.error("limit-count group ", conf.group,
+                               " conf mismatched on field: ", field)
                 return false, "group conf mismatched"
             end
         end
@@ -662,7 +660,6 @@ local function run_rate_limit(conf, rule, ctx, name, cost, 
dry_run)
     else
         metadata = metadata_defaults
     end
-    core.log.info("limit-count plugin-metadata: ", 
core.json.delay_encode(metadata))
 
     local set_limit_headers = construct_rate_limiting_headers(conf, rule, 
metadata)
     local set_header = not is_log_phase
diff --git a/apisix/plugins/loggly.lua b/apisix/plugins/loggly.lua
index ad57438e61..5367dae4b5 100644
--- a/apisix/plugins/loggly.lua
+++ b/apisix/plugins/loggly.lua
@@ -311,7 +311,7 @@ end
 
 local function handle_log(entries, conf)
     local metadata = plugin.plugin_metadata(plugin_name)
-    core.log.info("metadata: ", core.json.delay_encode(metadata))
+    core.log.info("metadata of plugin ", plugin_name, " found: ", metadata ~= 
nil)
 
     if not metadata then
         core.log.info("received nil metadata: using metadata defaults: ",
diff --git a/apisix/plugins/opentelemetry.lua b/apisix/plugins/opentelemetry.lua
index f1ebeea5bf..e0aa0e000f 100644
--- a/apisix/plugins/opentelemetry.lua
+++ b/apisix/plugins/opentelemetry.lua
@@ -381,7 +381,6 @@ function _M.rewrite(conf, api_ctx)
         core.log.warn("plugin_metadata is required for opentelemetry plugin to 
working properly")
         return
     end
-    core.log.info("metadata: ", core.json.delay_encode(metadata))
     local plugin_info = metadata.value
     local vars = api_ctx.var
 
diff --git a/apisix/plugins/proxy-cache/init.lua 
b/apisix/plugins/proxy-cache/init.lua
index cf23b05bd2..b96460f991 100644
--- a/apisix/plugins/proxy-cache/init.lua
+++ b/apisix/plugins/proxy-cache/init.lua
@@ -191,7 +191,7 @@ end
 
 
 function _M.access(conf, ctx)
-    core.log.info("proxy-cache plugin access phase, conf: ", 
core.json.delay_encode(conf))
+    core.log.info("proxy-cache plugin access phase")
 
     local value = util.generate_complex_value(conf.cache_key, ctx)
 
@@ -224,7 +224,7 @@ end
 
 
 function _M.header_filter(conf, ctx)
-    core.log.info("proxy-cache plugin header filter phase, conf: ", 
core.json.delay_encode(conf))
+    core.log.info("proxy-cache plugin header filter phase")
 
     local handler
     if conf.cache_strategy == STRATEGY_MEMORY then
@@ -238,7 +238,7 @@ end
 
 
 function _M.body_filter(conf, ctx)
-    core.log.info("proxy-cache plugin body filter phase, conf: ", 
core.json.delay_encode(conf))
+    core.log.info("proxy-cache plugin body filter phase")
 
     if conf.cache_strategy == STRATEGY_MEMORY then
         memory_handler.body_filter(conf, ctx)
diff --git a/apisix/plugins/proxy-mirror.lua b/apisix/plugins/proxy-mirror.lua
index a5e0d1fe4b..4d3bbe2ccc 100644
--- a/apisix/plugins/proxy-mirror.lua
+++ b/apisix/plugins/proxy-mirror.lua
@@ -120,7 +120,7 @@ end
 
 
 function _M.rewrite(conf, ctx)
-    core.log.info("proxy mirror plugin rewrite phase, conf: ", 
core.json.delay_encode(conf))
+    core.log.info("proxy mirror plugin rewrite phase")
 
     if conf.sample_ratio == 1 then
         enable_mirror(ctx, conf)
diff --git a/apisix/plugins/redirect.lua b/apisix/plugins/redirect.lua
index 1e1f338e70..a54008c089 100644
--- a/apisix/plugins/redirect.lua
+++ b/apisix/plugins/redirect.lua
@@ -188,7 +188,7 @@ local function get_port(attr)
 end
 
 function _M.rewrite(conf, ctx)
-    core.log.info("plugin rewrite phase, conf: ", core.json.delay_encode(conf))
+    core.log.info("plugin rewrite phase")
 
     local ret_code = conf.ret_code
 
diff --git a/apisix/plugins/traffic-split.lua b/apisix/plugins/traffic-split.lua
index 2eb492f062..aa089139fc 100644
--- a/apisix/plugins/traffic-split.lua
+++ b/apisix/plugins/traffic-split.lua
@@ -302,7 +302,6 @@ function _M.access(conf, ctx)
 
     local upstream = rr_up:find()
     if upstream and type(upstream) == "table" then
-        core.log.info("upstream: ", core.json.encode(upstream))
         return set_upstream(upstream, ctx)
     elseif upstream and upstream ~= "plugin#upstream#is#empty" then
         ctx.upstream_id = upstream
diff --git a/apisix/stream/plugins/mqtt-proxy.lua 
b/apisix/stream/plugins/mqtt-proxy.lua
index 8617cf64c4..031e3d98cd 100644
--- a/apisix/stream/plugins/mqtt-proxy.lua
+++ b/apisix/stream/plugins/mqtt-proxy.lua
@@ -179,7 +179,7 @@ end
 
 
 function _M.log(conf, ctx)
-    core.log.info("plugin log phase, conf: ", core.json.encode(conf))
+    core.log.info("plugin log phase")
 end
 
 
diff --git a/apisix/utils/log-util.lua b/apisix/utils/log-util.lua
index 2d998d8e44..e31f5256f3 100644
--- a/apisix/utils/log-util.lua
+++ b/apisix/utils/log-util.lua
@@ -305,7 +305,7 @@ function _M.get_log_entry(plugin_name, conf, ctx)
     end
 
     local metadata = plugin.plugin_metadata(plugin_name)
-    core.log.info("metadata: ", core.json.delay_encode(metadata))
+    core.log.info("metadata of plugin ", plugin_name, " found: ", metadata ~= 
nil)
 
     local entry
     local customized = false
diff --git a/t/node/data_encrypt_invalid_conf.t 
b/t/node/data_encrypt_invalid_conf.t
new file mode 100644
index 0000000000..f993199600
--- /dev/null
+++ b/t/node/data_encrypt_invalid_conf.t
@@ -0,0 +1,183 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_long_string();
+no_root_location();
+no_shuffle();
+log_level("warn");
+
+add_block_preprocessor(sub {
+    my ($block) = @_;
+
+    if (!$block->request) {
+        $block->set_value("request", "GET /t");
+    }
+
+    if (!$block->yaml_config) {
+        $block->set_value("yaml_config", <<_EOC_);
+apisix:
+    data_encryption:
+        enable_encrypt_fields: true
+        keyring:
+            - edd1c9f0985e76a2
+_EOC_
+    }
+});
+
+run_tests;
+
+__DATA__
+
+=== TEST 1: consumer with an invalid plugin, watch update
+--- config
+    location /t {
+        content_by_lua_block {
+            local core = require("apisix.core")
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/consumers',
+                ngx.HTTP_PUT,
+                [[{
+                    "username": "jack",
+                    "plugins": {
+                        "key-auth": {
+                            "key": "plaintext-consumer-key"
+                        }
+                    }
+                }]]
+            )
+            if code >= 300 then
+                ngx.status = code
+                ngx.say(body)
+                return
+            end
+
+            -- the Admin API rejects an invalid plugin, so write it to etcd 
directly
+            local res = assert(core.etcd.get("/consumers/jack"))
+            local consumer = res.body.node.value
+            consumer.plugins["limit-count"] = {count = -1, time_window = 60}
+            assert(core.etcd.set("/consumers/jack", consumer))
+            ngx.sleep(1)
+            ngx.say("done")
+        }
+    }
+--- response_body
+done
+--- error_log
+failed to check item data of [/apisix/consumers] err:failed to check the 
configuration of plugin limit-count
+key: /apisix/consumers/jack
+--- no_error_log
+plaintext-consumer-key
+
+
+
+=== TEST 2: consumer with an invalid plugin, cold start
+--- config
+    location /t {
+        content_by_lua_block {
+            ngx.sleep(1)
+            ngx.say("done")
+        }
+    }
+--- response_body
+done
+--- error_log
+failed to check item data of [/apisix/consumers] err:failed to check the 
configuration of plugin limit-count
+key: /apisix/consumers/jack
+--- no_error_log
+plaintext-consumer-key
+
+
+
+=== TEST 3: route whose vars fail after its plugins pass, watch update
+--- config
+    location /t {
+        content_by_lua_block {
+            local core = require("apisix.core")
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/consumers/jack', 
ngx.HTTP_DELETE)
+            if code >= 300 then
+                ngx.status = code
+                ngx.say(body)
+                return
+            end
+
+            code, body = t('/apisix/admin/routes/1',
+                ngx.HTTP_PUT,
+                [[{
+                    "uri": "/hello",
+                    "plugins": {
+                        "csrf": {
+                            "key": "plaintext-csrf-key"
+                        }
+                    },
+                    "upstream": {
+                        "type": "roundrobin",
+                        "nodes": {
+                            "127.0.0.1:1980": 1
+                        }
+                    }
+                }]]
+            )
+            if code >= 300 then
+                ngx.status = code
+                ngx.say(body)
+                return
+            end
+
+            -- the Admin API rejects invalid vars, so write them to etcd 
directly
+            local res = assert(core.etcd.get("/routes/1"))
+            local route = res.body.node.value
+            route.vars = {{"arg_k", "invalid-operator", "v"}}
+            assert(core.etcd.set("/routes/1", route))
+            ngx.sleep(1)
+            ngx.say("done")
+        }
+    }
+--- response_body
+done
+--- error_log
+failed to check item data of [/apisix/routes] err:failed to validate the 
'vars' expression
+key: /apisix/routes/1
+--- no_error_log
+plaintext-csrf-key
+
+
+
+=== TEST 4: route whose vars fail after its plugins pass, cold start
+--- config
+    location /t {
+        content_by_lua_block {
+            ngx.sleep(1)
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/routes/1', ngx.HTTP_DELETE)
+            if code >= 300 then
+                ngx.status = code
+                ngx.say(body)
+                return
+            end
+            ngx.say("done")
+        }
+    }
+--- response_body
+done
+--- error_log
+failed to check item data of [/apisix/routes] err:failed to validate the 
'vars' expression
+key: /apisix/routes/1
+--- no_error_log
+plaintext-csrf-key
diff --git a/t/node/merge-route.t b/t/node/merge-route.t
index b09b272cf7..409366dd35 100644
--- a/t/node/merge-route.t
+++ b/t/node/merge-route.t
@@ -221,8 +221,8 @@ location /t {
 --- request
 GET /t
 --- error_log eval
-[qr/merge_service_route.*"time_window":60/,
-qr/merge_service_route.*"time_window":60/]
+[qr/merge_service_route\(\): merge service \[1\] into route \[1\]/,
+qr/merge_service_route\(\): merge service \[1\] into route \[1\]/]
 
 
 
diff --git a/t/node/plugin-conf-log-secret.t b/t/node/plugin-conf-log-secret.t
new file mode 100644
index 0000000000..942ec90275
--- /dev/null
+++ b/t/node/plugin-conf-log-secret.t
@@ -0,0 +1,399 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_long_string();
+no_root_location();
+no_shuffle();
+log_level("info");
+
+add_block_preprocessor(sub {
+    my ($block) = @_;
+
+    if (!$block->request && !$block->stream_request) {
+        $block->set_value("request", "GET /t");
+    }
+
+    if (!$block->no_error_log) {
+        $block->set_value("no_error_log", 
"plaintext-redis-secret\nmarked-redis-secret");
+    }
+
+    # the marked cases enable data encryption so that the marked value is 
decrypted on load
+    if ($block->name =~ /marked/ && !$block->yaml_config) {
+        $block->set_value("yaml_config", <<_EOC_);
+apisix:
+    data_encryption:
+        enable_encrypt_fields: true
+        keyring:
+            - edd1c9f0985e76a2
+_EOC_
+    }
+
+    # write the resources straight to etcd, the way the control plane does
+    my $extra_init_by_lua = <<_EOC_;
+    function _G.mark(v)
+        local de = require("apisix.core").data_encryption
+        local keyring = de.init_iv_tbl({"edd1c9f0985e76a2"})
+        return "\$ENC\$v1\$" .. assert(de.aes_cbc_encrypt(keyring, v))
+    end
+    function _G.put(key, value)
+        assert(require("apisix.core").etcd.set(key, value))
+    end
+    function _G.del(key)
+        assert(require("apisix.core").etcd.delete(key))
+    end
+_EOC_
+    $block->set_value("extra_init_by_lua", $extra_init_by_lua);
+});
+
+run_tests;
+
+__DATA__
+
+=== TEST 1: stream route with a secret in its plugin conf, merged with a 
service
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/services/1',
+                ngx.HTTP_PUT,
+                [[{
+                    "upstream": {
+                        "type": "roundrobin",
+                        "nodes": {
+                            "127.0.0.1:1995": 1
+                        }
+                    }
+                }]]
+            )
+            if code >= 300 then
+                ngx.status = code
+                ngx.say(body)
+                return
+            end
+
+            code, body = t('/apisix/admin/stream_routes/1',
+                ngx.HTTP_PUT,
+                [[{
+                    "service_id": "1",
+                    "plugins": {
+                        "limit-conn": {
+                            "conn": 100,
+                            "burst": 50,
+                            "default_conn_delay": 0.1,
+                            "key": "remote_addr",
+                            "policy": "redis",
+                            "redis_host": "127.0.0.1",
+                            "redis_port": 1,
+                            "redis_password": "plaintext-redis-secret",
+                            "allow_degradation": true
+                        }
+                    }
+                }]]
+            )
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- response_body
+passed
+--- error_log
+check stream plugin schema, name: limit-conn
+
+
+
+=== TEST 2: load the stream route on start and hit it
+--- stream_request
+mmm
+--- stream_response
+hello world
+--- error_log
+check stream plugin schema, name: limit-conn
+merge service [1] into stream route [1]
+init plugin-level conf version
+
+
+
+=== TEST 3: plugin checker fails on an unrelated field, watch update
+--- config
+    location /t {
+        content_by_lua_block {
+            local core = require("apisix.core")
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/stream_routes/1', 
ngx.HTTP_DELETE)
+            if code >= 300 then
+                ngx.status = code
+                ngx.say(body)
+                return
+            end
+
+            code, body = t('/apisix/admin/routes/1',
+                ngx.HTTP_PUT,
+                [[{
+                    "uri": "/hello",
+                    "plugins": {
+                        "limit-count": {
+                            "count": 2,
+                            "time_window": 60,
+                            "policy": "redis",
+                            "redis_host": "127.0.0.1",
+                            "redis_password": "plaintext-redis-secret"
+                        }
+                    },
+                    "upstream": {
+                        "type": "roundrobin",
+                        "nodes": {
+                            "127.0.0.1:1980": 1
+                        }
+                    }
+                }]]
+            )
+            if code >= 300 then
+                ngx.status = code
+                ngx.say(body)
+                return
+            end
+
+            -- the Admin API rejects an invalid plugin, so write it to etcd 
directly
+            local res = assert(core.etcd.get("/routes/1"))
+            local route = res.body.node.value
+            route.plugins["response-rewrite"] = {status_code = 1}
+            assert(core.etcd.set("/routes/1", route))
+            ngx.sleep(1)
+            ngx.say("done")
+        }
+    }
+--- response_body
+done
+--- error_log
+failed to check item data of [/apisix/routes] err:failed to check the 
configuration of plugin response-rewrite
+key: /apisix/routes/1
+
+
+
+=== TEST 4: plugin checker fails on an unrelated field, full load
+--- config
+    location /t {
+        content_by_lua_block {
+            ngx.sleep(1)
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/routes/1', ngx.HTTP_DELETE)
+            if code >= 300 then
+                ngx.status = code
+                ngx.say(body)
+                return
+            end
+            code, body = t('/apisix/admin/services/1', ngx.HTTP_DELETE)
+            if code >= 300 then
+                ngx.status = code
+                ngx.say(body)
+                return
+            end
+            ngx.say("done")
+        }
+    }
+--- response_body
+done
+--- error_log
+failed to check item data of [/apisix/routes] err:failed to check the 
configuration of plugin response-rewrite
+key: /apisix/routes/1
+
+
+
+=== TEST 5: stream route with a marked secret in its plugin conf, merged with 
a service
+--- config
+    location /t {
+        content_by_lua_block {
+            put("/services/1", {
+                upstream = {nodes = {["127.0.0.1:1995"] = 1}, type = 
"roundrobin"},
+            })
+            put("/stream_routes/1", {
+                service_id = "1",
+                plugins = {
+                    ["limit-conn"] = {
+                        conn = 100,
+                        burst = 50,
+                        default_conn_delay = 0.1,
+                        key = "remote_addr",
+                        policy = "redis",
+                        redis_host = "127.0.0.1",
+                        redis_port = 1,
+                        redis_password = mark("marked-redis-secret"),
+                        allow_degradation = true,
+                    },
+                },
+            })
+            ngx.say("passed")
+        }
+    }
+--- response_body
+passed
+
+
+
+=== TEST 6: load the stream route with the marked secret on start and hit it
+--- stream_request
+mmm
+--- stream_response
+hello world
+--- error_log
+check stream plugin schema, name: limit-conn
+merge service [1] into stream route [1]
+init plugin-level conf version
+
+
+
+=== TEST 7: marked secret, plugin checker fails on an unrelated field, watch 
update
+--- config
+    location /t {
+        content_by_lua_block {
+            -- let the initial full load finish so that the route arrives 
through the watch
+            ngx.sleep(1)
+            del("/stream_routes/1")
+            del("/services/1")
+            put("/routes/1", {
+                uri = "/hello",
+                plugins = {
+                    ["limit-count"] = {
+                        count = 2,
+                        time_window = 60,
+                        policy = "redis",
+                        redis_host = "127.0.0.1",
+                        redis_password = mark("marked-redis-secret"),
+                    },
+                    ["response-rewrite"] = {status_code = 1},
+                },
+                upstream = {nodes = {["127.0.0.1:1980"] = 1}, type = 
"roundrobin"},
+            })
+            ngx.sleep(1)
+            ngx.say("done")
+        }
+    }
+--- response_body
+done
+--- error_log
+failed to check item data of [/apisix/routes] err:failed to check the 
configuration of plugin response-rewrite
+key: /apisix/routes/1
+
+
+
+=== TEST 8: marked secret, plugin checker fails on an unrelated field, full 
load
+--- config
+    location /t {
+        content_by_lua_block {
+            ngx.sleep(1)
+            del("/routes/1")
+            ngx.say("done")
+        }
+    }
+--- response_body
+done
+--- error_log
+failed to check item data of [/apisix/routes] err:failed to check the 
configuration of plugin response-rewrite
+key: /apisix/routes/1
+
+
+
+=== TEST 9: route fails the item schema, watch update
+--- config
+    location /t {
+        content_by_lua_block {
+            ngx.sleep(1)
+            put("/routes/1", {
+                uri = "/hello",
+                priority = "high",
+                plugins = {
+                    ["limit-count"] = {
+                        count = 2,
+                        time_window = 60,
+                        policy = "redis",
+                        redis_host = "127.0.0.1",
+                        redis_password = "plaintext-redis-secret",
+                    },
+                },
+                upstream = {nodes = {["127.0.0.1:1980"] = 1}, type = 
"roundrobin"},
+            })
+            ngx.sleep(1)
+            ngx.say("done")
+        }
+    }
+--- response_body
+done
+--- error_log
+failed to check item data of [/apisix/routes] err:property "priority" 
validation failed
+key: /apisix/routes/1
+
+
+
+=== TEST 10: route fails the item schema, full load
+--- config
+    location /t {
+        content_by_lua_block {
+            ngx.sleep(1)
+            del("/routes/1")
+            ngx.say("done")
+        }
+    }
+--- response_body
+done
+--- error_log
+failed to check item data of [/apisix/routes] err:property "priority" 
validation failed
+key: /apisix/routes/1
+
+
+
+=== TEST 11: non-table plugin conf, watch update
+--- config
+    location /t {
+        content_by_lua_block {
+            ngx.sleep(1)
+            put("/routes/1", {
+                uri = "/hello",
+                plugins = {
+                    ["limit-count"] = "plaintext-redis-secret",
+                },
+                upstream = {nodes = {["127.0.0.1:1980"] = 1}, type = 
"roundrobin"},
+            })
+            ngx.sleep(1)
+            ngx.say("done")
+        }
+    }
+--- response_body
+done
+--- error_log
+invalid plugin conf type string for plugin [limit-count]
+key: /apisix/routes/1
+
+
+
+=== TEST 12: non-table plugin conf, full load
+--- config
+    location /t {
+        content_by_lua_block {
+            ngx.sleep(1)
+            del("/routes/1")
+            ngx.say("done")
+        }
+    }
+--- response_body
+done
+--- error_log
+invalid plugin conf type string for plugin [limit-count]
+key: /apisix/routes/1
diff --git a/t/plugin/basic-auth.t b/t/plugin/basic-auth.t
index ffa94cf457..4b3fdd807a 100644
--- a/t/plugin/basic-auth.t
+++ b/t/plugin/basic-auth.t
@@ -311,7 +311,7 @@ qr/\{"error_msg":"invalid plugins configuration: failed to 
check the configurati
 GET /t
 --- error_code: 400
 --- response_body
-{"error_msg":"invalid plugins configuration: invalid plugin conf \"blah\" for 
plugin [basic-auth]"}
+{"error_msg":"invalid plugins configuration: invalid plugin conf type string 
for plugin [basic-auth]"}
 
 
 
diff --git a/t/plugin/ldap-auth.t b/t/plugin/ldap-auth.t
index 8b31aa6b6f..a4c1cc35e2 100644
--- a/t/plugin/ldap-auth.t
+++ b/t/plugin/ldap-auth.t
@@ -291,7 +291,7 @@ find consumer user01
     }
 --- response_body
 {"error_msg":"invalid plugins configuration: failed to check the configuration 
of plugin ldap-auth err: property \"user_dn\" is required"}
-{"error_msg":"invalid plugins configuration: invalid plugin conf \"blah\" for 
plugin [ldap-auth]"}
+{"error_msg":"invalid plugins configuration: invalid plugin conf type string 
for plugin [ldap-auth]"}
 
 
 
diff --git a/t/plugin/limit-count-redis2.t b/t/plugin/limit-count-redis2.t
index 35a51c1dbd..bd37e73e69 100644
--- a/t/plugin/limit-count-redis2.t
+++ b/t/plugin/limit-count-redis2.t
@@ -321,6 +321,7 @@ qr/X-RateLimit-Limit/
                             "redis_port": 6379,
                             "redis_database": 1,
                             "redis_timeout": 1001,
+                            "redis_password": "limit-count-group-secret",
                             "group": "redis"
                         }
                     },
@@ -354,6 +355,7 @@ qr/X-RateLimit-Limit/
                             "redis_port": 6379,
                             "redis_database": 2,
                             "redis_timeout": 1001,
+                            "redis_password": "limit-count-group-secret",
                             "group": "redis"
                         }
                     },
@@ -374,6 +376,8 @@ qr/X-RateLimit-Limit/
     }
 --- error_code: 400
 --- error_log
-[error]
+limit-count group redis conf mismatched on field: redis_database
+--- no_error_log eval
+qr/limit-count group .*limit-count-group-secret/
 --- response_body
 {"error_msg":"failed to check the configuration of plugin limit-count err: 
group conf mismatched"}
diff --git a/t/plugin/request-id3.t b/t/plugin/request-id3.t
index 2b8c2d3471..ade4c3b316 100644
--- a/t/plugin/request-id3.t
+++ b/t/plugin/request-id3.t
@@ -69,8 +69,8 @@ passed
 === TEST 2: hit
 --- request
 GET /opentracing
---- error_log
-X-Request-Id
+--- response_headers_like
+X-Request-Id: [0-9a-zA-Z]{27}
 --- no_error_log
 [error]
 
diff --git a/t/plugin/traffic-split5.t b/t/plugin/traffic-split5.t
index d029d26032..a655b566d8 100644
--- a/t/plugin/traffic-split5.t
+++ b/t/plugin/traffic-split5.t
@@ -699,6 +699,8 @@ passed
 GET /server_port
 --- response_body chomp
 1983
+--- no_error_log eval
+qr/traffic-split\.lua:\d+: .*PRIVATE KEY/
 
 
 
diff --git a/t/script/script.t b/t/script/script.t
index 0a0d90e626..62959fab31 100644
--- a/t/script/script.t
+++ b/t/script/script.t
@@ -96,4 +96,4 @@ hello world
 --- error_log eval
 qr/loaded script_obj: \{"access":"function: 0x[\w]+"\}/
 --- no_error_log eval
-qr/plugin rewrite phase, conf: \{"i":1\}/
+qr/plugin rewrite phase/

Reply via email to