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

moonming pushed a commit to branch fix/hmac-auth-digest-signed-headers
in repository https://gitbox.apache.org/repos/asf/apisix.git

commit fe7d0238a383bb13e198968ae7a877c746cc09c8
Author: Ming Wen <[email protected]>
AuthorDate: Tue Nov 24 13:54:36 2026 +0800

    fix: strengthen digest compatibility handling
---
 apisix/plugins/hmac-auth.lua | 10 ++++++----
 t/plugin/hmac-auth3.t        | 11 ++++++++++-
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/apisix/plugins/hmac-auth.lua b/apisix/plugins/hmac-auth.lua
index f4272c7312..2cb89656d6 100644
--- a/apisix/plugins/hmac-auth.lua
+++ b/apisix/plugins/hmac-auth.lua
@@ -31,9 +31,10 @@ local resty_sha256 = require("resty.sha256")
 local schema_def = require("apisix.schema_def")
 local auth_utils = require("apisix.utils.auth")
 local string_lower = string.lower
-local setmetatable = setmetatable
+local tostring = tostring
+local lrucache = require("resty.lrucache")
 
-local legacy_unsigned_digest_warned = setmetatable({}, {__mode = "k"})
+local legacy_unsigned_digest_warned = lrucache.new(1024)
 
 local schema = {
     type = "object",
@@ -307,9 +308,10 @@ local function validate(ctx, conf, params)
         if ctx.matched_route and ctx.matched_route.value.service_id then
             warning_key = ctx.matched_route.value.service_id
         end
+        warning_key = tostring(warning_key)
         if not has_signed_header(params.headers, "digest")
-           and not legacy_unsigned_digest_warned[warning_key] then
-            legacy_unsigned_digest_warned[warning_key] = true
+           and not legacy_unsigned_digest_warned:get(warning_key) then
+            legacy_unsigned_digest_warned:set(warning_key, true)
             core.log.warn("hmac-auth accepted a request whose Digest header 
was not signed; ",
                           "this compatibility behavior will be removed in a 
future release")
         end
diff --git a/t/plugin/hmac-auth3.t b/t/plugin/hmac-auth3.t
index 0b7a348ebd..d540489b1e 100644
--- a/t/plugin/hmac-auth3.t
+++ b/t/plugin/hmac-auth3.t
@@ -579,6 +579,8 @@ qr/validate_request_body requires 'digest' in 
signed_headers/
             local hmac = require("resty.hmac")
             local resty_sha256 = require("resty.sha256")
 
+            assert(core.etcd.delete("/routes/1"))
+
             local code, body = t.test('/apisix/admin/routes/multi-valid', 
ngx.HTTP_PUT, [[{
                 "plugins": {
                     "multi-auth": {
@@ -635,6 +637,8 @@ passed
             local hmac = require("resty.hmac")
             local resty_sha256 = require("resty.sha256")
 
+            assert(core.etcd.delete("/routes/multi-valid"))
+
             local code, body = t.test('/apisix/admin/routes/mixed-case', 
ngx.HTTP_PUT, [[{
                 "plugins": {
                     "hmac-auth": {
@@ -692,7 +696,12 @@ passed
             assert(core.etcd.set("/services/shared-hmac", {
                 id = "shared-hmac",
                 plugins = {
-                    ["hmac-auth"] = {validate_request_body = true}
+                    ["multi-auth"] = {
+                        auth_plugins = {
+                            {["key-auth"] = {}},
+                            {["hmac-auth"] = {validate_request_body = true}},
+                        },
+                    },
                 },
                 upstream = {
                     nodes = {["127.0.0.1:1980"] = 1},

Reply via email to