spacewander commented on a change in pull request #2749:
URL: https://github.com/apache/apisix/pull/2749#discussion_r524851784



##########
File path: apisix/plugins/hmac-auth.lua
##########
@@ -194,14 +209,28 @@ local function generate_signature(ctx, secret_key, params)
         end
         core.table.sort(keys)
 
+        local field_val = get_conf_field(params.access_key, "enable_encode")
+        core.log.info("enable_encode: ", field_val)
+
         for _, key in pairs(keys) do
             local param = args[key]
-            if type(param) == "table" then
-                for _, val in pairs(param) do
-                    core.table.insert(query_tab, escape_uri(key) .. "=" .. 
escape_uri(val))
+            -- whether to escape the uri parameters
+            if field_val then

Review comment:
       Actually I mean this change:
   ```diff
   diff --git apisix/plugins/hmac-auth.lua apisix/plugins/hmac-auth.lua
   index bc09d21..45cc0cc 100644
   --- apisix/plugins/hmac-auth.lua
   +++ apisix/plugins/hmac-auth.lua
   @@ -190,6 +190,11 @@ local function get_conf_field(access_key, field_name)
    end
   
   
   +local function do_nothing(v)
   +    return v
   +end
   +
   +
    local function generate_signature(ctx, secret_key, params)
        local canonical_uri = ctx.var.uri
        local canonical_query_string = ""
   @@ -212,25 +217,22 @@ local function generate_signature(ctx, secret_key, 
params)
            local encode_or_not = get_conf_field(params.access_key, 
"encode_uri_params")
            core.log.info("encode_uri_params: ", encode_or_not)
   
   +        local encode_uri_param = do_nothing
   +        if encode_or_not then
   +            encode_uri_param = escape_uri
   +        end
   +
            for _, key in pairs(keys) do
                local param = args[key]
                -- whether to encode the uri parameters
   -            if encode_or_not then
   -                if type(param) == "table" then
   -                    for _, val in pairs(param) do
   -                        core.table.insert(query_tab, escape_uri(key) .. "=" 
.. escape_uri(val))
   -                    end
   -                else
   -                    core.table.insert(query_tab, escape_uri(key) .. "=" .. 
escape_uri(param))
   +            if type(param) == "table" then
   +                for _, val in pairs(param) do
   +                    core.table.insert(query_tab, encode_uri_param(key) .. 
"="
   +                                      .. encode_uri_param(val))
                    end
                else
   -                if type(param) == "table" then
   -                    for _, val in pairs(param) do
   -                        core.table.insert(query_tab, key .. "=" .. val)
   -                    end
   -                else
   -                    core.table.insert(query_tab, key .. "=" .. param)
   -                end
   +                core.table.insert(query_tab, encode_uri_param(key) .. "="
   +                                  .. encode_uri_param(param))
                end
            end
            canonical_query_string = core.table.concat(query_tab, "&")
   ```
   
   You can integrate it into your code.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to