You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/02/14 06:38:58 UTC

[GitHub] [apisix] kevinw66 opened a new pull request #6314: fix(hmac-auth): hmac-auth plugin sort array param

kevinw66 opened a new pull request #6314:
URL: https://github.com/apache/apisix/pull/6314


   ### What this PR does / why we need it:
   <!--- Why is this change required? What problem does it solve? -->
   <!--- If it fixes an open issue, please link to the issue here. -->
   
   fixes #6313 
   
   ### Pre-submission checklist:
   
   <!--
   Please follow the PR manners:
   1. Use Draft if the PR is not ready to be reviewed
   2. Test is required for the feat/fix PR, unless you have a good reason
   3. Doc is required for the feat PR
   4. Use a new commit to resolve review instead of `push -f`
   5. If you need to resolve merge conflicts after the PR is reviewed, please merge master but do not rebase
   6. Use "request review" to notify the reviewer once you have resolved the review
   7. Only reviewer can click "Resolve conversation" to mark the reviewer's review resolved
   -->
   
   * [ ] Did you explain what problem does this PR solve? Or what new features have been added?
   * [ ] Have you added corresponding test cases?
   * [ ] Have you modified the corresponding document?
   * [ ] Is this PR backward compatible? **If it is not backward compatible, please discuss on the [mailing list](https://github.com/apache/apisix/tree/master#community) first**
   


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] bisakhmondal commented on pull request #6314: fix(hmac-auth): hmac-auth plugin sort array param

Posted by GitBox <gi...@apache.org>.
bisakhmondal commented on pull request #6314:
URL: https://github.com/apache/apisix/pull/6314#issuecomment-1039222683


   Hi! Thanks for detecting the issue and the PR.
   After looking into the codebase, I find the way of forming the canonical query string unnecessarily complex yet it's not accurate. 
   I would go with a simpler approach rather than pathing this up. 
   
   We can replace:
   https://github.com/apache/apisix/blob/605141cba33beccf71100fdea03c8e9608d4852f/apisix/plugins/hmac-auth.lua#L219-L255
   with 
   https://github.com/apache/apisix/blob/605141cba33beccf71100fdea03c8e9608d4852f/apisix/plugins/aws-lambda.lua#L123-L130
   It's very simple, yet effective.
   cc @spacewander to share your views.


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] kevinw66 commented on a change in pull request #6314: fix(hmac-auth): hmac-auth plugin sort array param

Posted by GitBox <gi...@apache.org>.
kevinw66 commented on a change in pull request #6314:
URL: https://github.com/apache/apisix/pull/6314#discussion_r806540816



##########
File path: apisix/plugins/hmac-auth.lua
##########
@@ -244,7 +244,13 @@ local function generate_signature(ctx, secret_key, params)
 
             -- whether to encode the uri parameters
             if type(param) == "table" then
+                local vals = {}
                 for _, val in pairs(param) do
+                    core.table.insert(vals, val)

Review comment:
       done




-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] kevinw66 commented on pull request #6314: fix(hmac-auth): hmac-auth plugin sort array param

Posted by GitBox <gi...@apache.org>.
kevinw66 commented on pull request #6314:
URL: https://github.com/apache/apisix/pull/6314#issuecomment-1039754106






-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on a change in pull request #6314: fix(hmac-auth): hmac-auth plugin sort array param

Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #6314:
URL: https://github.com/apache/apisix/pull/6314#discussion_r806493438



##########
File path: apisix/plugins/hmac-auth.lua
##########
@@ -244,7 +244,13 @@ local function generate_signature(ctx, secret_key, params)
 
             -- whether to encode the uri parameters
             if type(param) == "table" then
+                local vals = {}
                 for _, val in pairs(param) do
+                    core.table.insert(vals, val)

Review comment:
       Remember to convert boolean to `''` before sorting. `table.sort` only supports sorting in the same type.




-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on a change in pull request #6314: fix(hmac-auth): hmac-auth plugin sort array param

Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #6314:
URL: https://github.com/apache/apisix/pull/6314#discussion_r806493438



##########
File path: apisix/plugins/hmac-auth.lua
##########
@@ -244,7 +244,13 @@ local function generate_signature(ctx, secret_key, params)
 
             -- whether to encode the uri parameters
             if type(param) == "table" then
+                local vals = {}
                 for _, val in pairs(param) do
+                    core.table.insert(vals, val)

Review comment:
       Remember to convert boolean to `''` before sorting. `table.sort` only supports sorting in the same type.




-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] kevinw66 commented on pull request #6314: fix(hmac-auth): hmac-auth plugin sort array param

Posted by GitBox <gi...@apache.org>.
kevinw66 commented on pull request #6314:
URL: https://github.com/apache/apisix/pull/6314#issuecomment-1039754106


   > Hi, @kevinw66.Can you add a test case to cover it.
   
   Can you teach me how to run unit tests in my local machine ? I left a comment on issue.
   Thanks. 


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tzssangglass commented on a change in pull request #6314: fix(hmac-auth): hmac-auth plugin sort array param

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on a change in pull request #6314:
URL: https://github.com/apache/apisix/pull/6314#discussion_r807472751



##########
File path: apisix/plugins/hmac-auth.lua
##########
@@ -244,7 +244,13 @@ local function generate_signature(ctx, secret_key, params)
 
             -- whether to encode the uri parameters
             if type(param) == "table" then
+                local vals = {}

Review comment:
       Not necessary to keep old code style here. We can specify the initialization size when we create a new table by using `core.table.new(narray, nhash)`




-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] bisakhmondal commented on pull request #6314: fix(hmac-auth): hmac-auth plugin sort array param

Posted by GitBox <gi...@apache.org>.
bisakhmondal commented on pull request #6314:
URL: https://github.com/apache/apisix/pull/6314#issuecomment-1041512925


   > This may still need to check table param
   > 
   > ```lua
   > for k, v in pairs(args) do
   >     if type(v) == "table" then
   >         for _, sv in pairs(v) do
   >             canonical_qs[#canonical_qs+1] = ngx.unescape_uri(k) .. "=" .. ngx.unescape_uri(sv)
   >         end
   >     else
   >         canonical_qs[#canonical_qs+1] = ngx.unescape_uri(k) .. "=" .. ngx.unescape_uri(v)
   >     end
   > end
   > ```
   
   Ohh, Thanks! I missed the scenario : )
   Btw, in that case,  something still looks odd! We are considering one extra level nesting in query params. Query params with nesting level > 2 would fail. 
   
   For example: (random example, taken from web)
   ```json
   main_key[other_key][main_array][0][name]=Bob&main_key[other_key][main_array][0][nickname]=bobby&main_key[other_key][main_array][1][name]=Tom&main_key[other_key][main_array][1][nickname]=Tommy
   
   {
       "main_key": {
           "other_key": {
               "main_array": [{
                       "name": "Bob",
                       "nickname": "bobby"
                   },
                   {
                       "name": "Tom",
                       "nickname": "Tommy"
                   }
               ]
           }
       }
   }
   
   ```
   
   I think we need to perform a recursive DFS! Else it will introduce some sort of indeterminism
   ```shell
   🔥➜ ~ resty -e 'print(ngx.escape_uri({["a"]="b"}))' 
   
   table%3A%200x7f5aa8abc608
   🔥➜ ~ resty -e 'print(ngx.escape_uri({["a"]="b"}))'
   
   table%3A%200x7f7eca005608
   ```


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] kevinw66 commented on pull request #6314: fix(hmac-auth): hmac-auth plugin sort array param

Posted by GitBox <gi...@apache.org>.
kevinw66 commented on pull request #6314:
URL: https://github.com/apache/apisix/pull/6314#issuecomment-1039764699


   > 
   
   
   
   > Hi! Thanks for detecting the issue and the PR. After looking into the codebase, I find the way of forming the canonical query string unnecessarily complex yet it's not accurate. I would go with a simpler approach rather than pathing this up.
   > 
   > We can replace:
   > 
   > https://github.com/apache/apisix/blob/605141cba33beccf71100fdea03c8e9608d4852f/apisix/plugins/hmac-auth.lua#L219-L255
   > 
   > 
   > with
   > https://github.com/apache/apisix/blob/605141cba33beccf71100fdea03c8e9608d4852f/apisix/plugins/aws-lambda.lua#L123-L130
   > 
   > 
   > It's very simple, yet effective.
   > cc @spacewander to share your views.
   
   This may still need to check table param
   ```lua
   for k, v in pairs(args) do
       if type(v) == "table" then
           for _, sv in pairs(v) do
               canonical_qs[#canonical_qs+1] = ngx.unescape_uri(k) .. "=" .. ngx.unescape_uri(sv)
           end
       else
           canonical_qs[#canonical_qs+1] = ngx.unescape_uri(k) .. "=" .. ngx.unescape_uri(v)
       end
   end
   ```


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] bisakhmondal commented on pull request #6314: fix(hmac-auth): hmac-auth plugin sort array param

Posted by GitBox <gi...@apache.org>.
bisakhmondal commented on pull request #6314:
URL: https://github.com/apache/apisix/pull/6314#issuecomment-1039222683


   Hi! Thanks for detecting the issue and the PR.
   After looking into the codebase, I find the way of forming the canonical query string unnecessarily complex yet it's not accurate. 
   I would go with a simpler approach rather than pathing this up. 
   
   We can replace:
   https://github.com/apache/apisix/blob/605141cba33beccf71100fdea03c8e9608d4852f/apisix/plugins/hmac-auth.lua#L219-L255
   with 
   https://github.com/apache/apisix/blob/605141cba33beccf71100fdea03c8e9608d4852f/apisix/plugins/aws-lambda.lua#L123-L130
   It's very simple, yet effective.
   cc @spacewander to share your views.


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on pull request #6314: fix(hmac-auth): hmac-auth plugin sort array param

Posted by GitBox <gi...@apache.org>.
spacewander commented on pull request #6314:
URL: https://github.com/apache/apisix/pull/6314#issuecomment-1039915404


   > Hi! Thanks for detecting the issue and the PR. After looking into the codebase, I find the way of forming the canonical query string unnecessarily complex yet it's not accurate. I would go with a simpler approach rather than pathing this up.
   > 
   > We can replace:
   > 
   > https://github.com/apache/apisix/blob/605141cba33beccf71100fdea03c8e9608d4852f/apisix/plugins/hmac-auth.lua#L219-L255
   > 
   > with
   > 
   > https://github.com/apache/apisix/blob/605141cba33beccf71100fdea03c8e9608d4852f/apisix/plugins/aws-lambda.lua#L123-L130
   > 
   > It's very simple, yet effective.
   > cc @spacewander to share your views.
   
   Yes, the way in aws-lambda still needs to handle multiple values in the same query key.
   
   


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] kevinw66 commented on a change in pull request #6314: fix(hmac-auth): hmac-auth plugin sort array param

Posted by GitBox <gi...@apache.org>.
kevinw66 commented on a change in pull request #6314:
URL: https://github.com/apache/apisix/pull/6314#discussion_r806540816



##########
File path: apisix/plugins/hmac-auth.lua
##########
@@ -244,7 +244,13 @@ local function generate_signature(ctx, secret_key, params)
 
             -- whether to encode the uri parameters
             if type(param) == "table" then
+                local vals = {}
                 for _, val in pairs(param) do
+                    core.table.insert(vals, val)

Review comment:
       done




-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] bisakhmondal removed a comment on pull request #6314: fix(hmac-auth): hmac-auth plugin sort array param

Posted by GitBox <gi...@apache.org>.
bisakhmondal removed a comment on pull request #6314:
URL: https://github.com/apache/apisix/pull/6314#issuecomment-1039222683


   Hi! Thanks for detecting the issue and the PR.
   After looking into the codebase, I find the way of forming the canonical query string unnecessarily complex yet it's not accurate. 
   I would go with a simpler approach rather than pathing this up. 
   
   We can replace:
   https://github.com/apache/apisix/blob/605141cba33beccf71100fdea03c8e9608d4852f/apisix/plugins/hmac-auth.lua#L219-L255
   with 
   https://github.com/apache/apisix/blob/605141cba33beccf71100fdea03c8e9608d4852f/apisix/plugins/aws-lambda.lua#L123-L130
   It's very simple, yet effective.
   cc @spacewander to share your views.


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] bisakhmondal removed a comment on pull request #6314: fix(hmac-auth): hmac-auth plugin sort array param

Posted by GitBox <gi...@apache.org>.
bisakhmondal removed a comment on pull request #6314:
URL: https://github.com/apache/apisix/pull/6314#issuecomment-1039222683


   Hi! Thanks for detecting the issue and the PR.
   After looking into the codebase, I find the way of forming the canonical query string unnecessarily complex yet it's not accurate. 
   I would go with a simpler approach rather than pathing this up. 
   
   We can replace:
   https://github.com/apache/apisix/blob/605141cba33beccf71100fdea03c8e9608d4852f/apisix/plugins/hmac-auth.lua#L219-L255
   with 
   https://github.com/apache/apisix/blob/605141cba33beccf71100fdea03c8e9608d4852f/apisix/plugins/aws-lambda.lua#L123-L130
   It's very simple, yet effective.
   cc @spacewander to share your views.


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on pull request #6314: fix(hmac-auth): hmac-auth plugin sort array param

Posted by GitBox <gi...@apache.org>.
spacewander commented on pull request #6314:
URL: https://github.com/apache/apisix/pull/6314#issuecomment-1039915404


   > Hi! Thanks for detecting the issue and the PR. After looking into the codebase, I find the way of forming the canonical query string unnecessarily complex yet it's not accurate. I would go with a simpler approach rather than pathing this up.
   > 
   > We can replace:
   > 
   > https://github.com/apache/apisix/blob/605141cba33beccf71100fdea03c8e9608d4852f/apisix/plugins/hmac-auth.lua#L219-L255
   > 
   > with
   > 
   > https://github.com/apache/apisix/blob/605141cba33beccf71100fdea03c8e9608d4852f/apisix/plugins/aws-lambda.lua#L123-L130
   > 
   > It's very simple, yet effective.
   > cc @spacewander to share your views.
   
   Yes, the way in aws-lambda still needs to handle multiple values in the same query key.
   
   


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] kevinw66 commented on a change in pull request #6314: fix(hmac-auth): hmac-auth plugin sort array param

Posted by GitBox <gi...@apache.org>.
kevinw66 commented on a change in pull request #6314:
URL: https://github.com/apache/apisix/pull/6314#discussion_r805674103



##########
File path: apisix/plugins/hmac-auth.lua
##########
@@ -244,7 +244,13 @@ local function generate_signature(ctx, secret_key, params)
 
             -- whether to encode the uri parameters
             if type(param) == "table" then
+                local vals = {}

Review comment:
       Just keep the same code style like table `keys`




-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander merged pull request #6314: fix(hmac-auth): hmac-auth plugin sort array param

Posted by GitBox <gi...@apache.org>.
spacewander merged pull request #6314:
URL: https://github.com/apache/apisix/pull/6314


   


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on pull request #6314: fix(hmac-auth): hmac-auth plugin sort array param

Posted by GitBox <gi...@apache.org>.
spacewander commented on pull request #6314:
URL: https://github.com/apache/apisix/pull/6314#issuecomment-1041525681


   AFAIK, the `ngx.req.get_uri_args` only returns two level table at most.
   
   
   > Multiple occurrences of an argument key will result in a table value holding all the values for that key in order.
   
   https://github.com/openresty/lua-nginx-module#ngxreqget_uri_args
   
   Here is the source: https://github.com/openresty/lua-resty-core/blob/97d2e5e08d9ddf328e33d2b5f1710a9ce3d8bbd0/lib/resty/core/request.lua#L237


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tylitianrui commented on a change in pull request #6314: fix(hmac-auth): hmac-auth plugin sort array param

Posted by GitBox <gi...@apache.org>.
tylitianrui commented on a change in pull request #6314:
URL: https://github.com/apache/apisix/pull/6314#discussion_r805667916



##########
File path: apisix/plugins/hmac-auth.lua
##########
@@ -244,7 +244,13 @@ local function generate_signature(ctx, secret_key, params)
 
             -- whether to encode the uri parameters
             if type(param) == "table" then
+                local vals = {}

Review comment:
       i  wonder that  why not use table.new




-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] kevinw66 commented on pull request #6314: fix(hmac-auth): hmac-auth plugin sort array param

Posted by GitBox <gi...@apache.org>.
kevinw66 commented on pull request #6314:
URL: https://github.com/apache/apisix/pull/6314#issuecomment-1039771809


   > Hi! Thanks for detecting the issue and the PR. After looking into the codebase, I find the way of forming the canonical query string unnecessarily complex yet it's not accurate. I would go with a simpler approach rather than pathing this up.
   > 
   > We can replace:
   > 
   > https://github.com/apache/apisix/blob/605141cba33beccf71100fdea03c8e9608d4852f/apisix/plugins/hmac-auth.lua#L219-L255
   > 
   > 
   > with
   > https://github.com/apache/apisix/blob/605141cba33beccf71100fdea03c8e9608d4852f/apisix/plugins/aws-lambda.lua#L123-L130
   > 
   > 
   > It's very simple, yet effective.
   > cc @spacewander to share your views.
   
   This may not work correctly in some cases, in ASCII table, the '=' symbol is behind number sequence, so if I pass param like `a1a=2&a1a=1&a=2`, it will sort as `a1a=1&a1a=2&a=2`, but I think the result `a=2&a1a=1&a1a=2` may correct.


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org