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

shreemaan-abhishek 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 51bf1fb71 fix(basic-auth): validate anonymous_consumer against schema 
(#13682)
51bf1fb71 is described below

commit 51bf1fb71cccc7c4168783a01dfc65ea524b84ca
Author: Shreemaan Abhishek <[email protected]>
AuthorDate: Mon Jul 13 11:32:04 2026 +0800

    fix(basic-auth): validate anonymous_consumer against schema (#13682)
---
 apisix/plugins/basic-auth.lua            |  2 +-
 t/plugin/basic-auth-anonymous-consumer.t | 22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/apisix/plugins/basic-auth.lua b/apisix/plugins/basic-auth.lua
index a6a90d98c..5d3f46a94 100644
--- a/apisix/plugins/basic-auth.lua
+++ b/apisix/plugins/basic-auth.lua
@@ -34,8 +34,8 @@ local schema = {
             default = false,
         },
         realm = schema_def.get_realm_schema("basic"),
+        anonymous_consumer = schema_def.anonymous_consumer_schema,
     },
-    anonymous_consumer = schema_def.anonymous_consumer_schema,
 }
 
 local consumer_schema = {
diff --git a/t/plugin/basic-auth-anonymous-consumer.t 
b/t/plugin/basic-auth-anonymous-consumer.t
index 64a84f05f..5f59f5d9d 100644
--- a/t/plugin/basic-auth-anonymous-consumer.t
+++ b/t/plugin/basic-auth-anonymous-consumer.t
@@ -222,3 +222,25 @@ GET /hello
 failed to get anonymous consumer not-found-anonymous
 --- response_body
 {"message":"Invalid user authorization"}
+
+
+
+=== TEST 8: anonymous_consumer must be a non-empty string
+--- config
+    location /t {
+        content_by_lua_block {
+            local plugin = require("apisix.plugins.basic-auth")
+            local values = {123, true, {}, ""}
+            for _, value in ipairs(values) do
+                local ok, err = plugin.check_schema({anonymous_consumer = 
value})
+                ngx.say(ok, " ", err)
+            end
+        }
+    }
+--- request
+GET /t
+--- response_body
+false property "anonymous_consumer" validation failed: wrong type: expected 
string, got number
+false property "anonymous_consumer" validation failed: wrong type: expected 
string, got boolean
+false property "anonymous_consumer" validation failed: wrong type: expected 
string, got table
+false property "anonymous_consumer" validation failed: string too short, 
expected at least 1, got 0

Reply via email to