You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "SkyeYoung (via GitHub)" <gi...@apache.org> on 2025/08/20 08:01:48 UTC

[PR] fix: basic auth scheme supports case insensitivity [apisix]

SkyeYoung opened a new pull request, #12539:
URL: https://github.com/apache/apisix/pull/12539

   ### Description
   
   <!-- Please include a summary of the change and which issue is fixed. -->
   <!-- Please also include relevant motivation and context. -->
   The parsing part is reimplemented with reference to the following rfcs:
   
   * https://datatracker.ietf.org/doc/html/rfc7235
   * https://datatracker.ietf.org/doc/html/rfc9110
   * https://datatracker.ietf.org/doc/html/rfc5234
   
   It should be noted that the original Http header field name part can handle case-insensitivity, so this PR focuses on processing the Http header field value part.
   
   Currently, the implementation of this PR mainly refers to:
   
   https://github.com/apache/apisix/blob/12b0824e23e82ee097dcdd3fa7faafe35dc674c8/apisix/plugins/openid-connect.lua#L393-407
   
   
   #### Which issue(s) this PR fixes:
   <!--
   *Automatically closes linked issue when PR is merged.
   Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
   -->
   Fixes #11837 
   
   ### Checklist
   
   - [x] I have explained the need for this PR and the problem it solves
   - [x] I have explained the changes or the new features added to this PR
   - [x] I have added tests corresponding to this change
   - [ ] I have updated the documentation to reflect this change
   - [ x I have verified that this change is backward compatible (If not, please discuss on the [APISIX mailing list](https://github.com/apache/apisix/tree/master#community) first)
   
   <!--
   
   Note
   
   1. Mark the PR as draft until it's ready to be reviewed.
   2. Always add/update tests for any changes unless you have a good reason.
   3. Always update the documentation to reflect the changes made in the PR.
   4. Make a new commit to resolve conversations instead of `push -f`.
   5. To resolve merge conflicts, merge master instead of rebasing.
   6. Use "request review" to notify the reviewer after making changes.
   7. Only a reviewer can mark a conversation as resolved.
   
   -->
   


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


Re: [PR] fix: basic auth scheme supports case insensitivity [apisix]

Posted by "SkyeYoung (via GitHub)" <gi...@apache.org>.
SkyeYoung commented on code in PR #12539:
URL: https://github.com/apache/apisix/pull/12539#discussion_r2292455045


##########
apisix/plugins/ldap-auth.lua:
##########
@@ -66,23 +67,27 @@ function _M.check_schema(conf, schema_type)
     return ok, err
 end
 
-local function extract_auth_header(authorization)
+local function extract_auth_header(auth)
     local obj = { username = "", password = "" }
+    -- Check format of Authorization header.
+    local matches, err = ngx_re.split(auth, "\\s+", nil, nil, 2)
 
-    local m, err = ngx.re.match(authorization, "Basic\\s(.+)", "jo")

Review Comment:
   The current implementation refers to https://github.com/apache/apisix/blob/12b0824e23e82ee097dcdd3fa7faafe35dc674c8/apisix/plugins/openid-connect.lua#L393-L407.
   
   But as you said, it is indeed much simpler in terms of syntax.
   
   I may need to try it to determine their performance.



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


Re: [PR] fix: basic auth scheme supports case insensitivity [apisix]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #12539:
URL: https://github.com/apache/apisix/pull/12539#discussion_r2289993302


##########
apisix/plugins/basic-auth.lua:
##########
@@ -20,6 +20,7 @@ local ngx_re = require("ngx.re")
 local consumer = require("apisix.consumer")
 local schema_def = require("apisix.schema_def")
 local auth_utils = require("apisix.utils.auth")
+local string = string

Review Comment:
   [nitpick] Creating a local alias for the global `string` module is unnecessary since `string.lower` is only used once in this file. Consider using `string.lower` directly to avoid the redundant local declaration.
   ```suggestion
   
   ```



##########
apisix/plugins/ldap-auth.lua:
##########
@@ -19,6 +19,7 @@ local ngx = ngx
 local ngx_re = require("ngx.re")
 local consumer_mod = require("apisix.consumer")
 local ldap = require("resty.ldap")
+local string = string

Review Comment:
   [nitpick] Creating a local alias for the global `string` module is unnecessary since `string.lower` is only used once in this file. Consider using `string.lower` directly to avoid the redundant local declaration.
   ```suggestion
   
   ```



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


Re: [PR] fix: basic auth scheme supports case insensitivity [apisix]

Posted by "SkyeYoung (via GitHub)" <gi...@apache.org>.
SkyeYoung commented on code in PR #12539:
URL: https://github.com/apache/apisix/pull/12539#discussion_r2297399136


##########
apisix/plugins/ldap-auth.lua:
##########
@@ -66,23 +67,27 @@ function _M.check_schema(conf, schema_type)
     return ok, err
 end
 
-local function extract_auth_header(authorization)
+local function extract_auth_header(auth)
     local obj = { username = "", password = "" }
+    -- Check format of Authorization header.
+    local matches, err = ngx_re.split(auth, "\\s+", nil, nil, 2)
 
-    local m, err = ngx.re.match(authorization, "Basic\\s(.+)", "jo")

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


Re: [PR] fix: basic auth scheme supports case insensitivity [apisix]

Posted by "SkyeYoung (via GitHub)" <gi...@apache.org>.
SkyeYoung commented on code in PR #12539:
URL: https://github.com/apache/apisix/pull/12539#discussion_r2292455045


##########
apisix/plugins/ldap-auth.lua:
##########
@@ -66,23 +67,27 @@ function _M.check_schema(conf, schema_type)
     return ok, err
 end
 
-local function extract_auth_header(authorization)
+local function extract_auth_header(auth)
     local obj = { username = "", password = "" }
+    -- Check format of Authorization header.
+    local matches, err = ngx_re.split(auth, "\\s+", nil, nil, 2)
 
-    local m, err = ngx.re.match(authorization, "Basic\\s(.+)", "jo")

Review Comment:
   The current implementation refers to https://github.com/apache/apisix/blob/12b0824e23e82ee097dcdd3fa7faafe35dc674c8/apisix/plugins/openid-connect.lua#L393-L407, but as you said, it is indeed much simpler in terms of syntax.
   
   I may need to try it to determine their performance.



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


Re: [PR] fix: basic auth scheme supports case insensitivity [apisix]

Posted by "bzp2010 (via GitHub)" <gi...@apache.org>.
bzp2010 commented on code in PR #12539:
URL: https://github.com/apache/apisix/pull/12539#discussion_r2291031797


##########
t/plugin/basic-auth.t:
##########
@@ -252,7 +288,7 @@ GET /t
 
 
 
-=== TEST 13: invalid schema, not field given
+=== TEST 16: invalid schema, not field given

Review Comment:
   Do these tests need to be added in the middle? Can it be in a new file or at the end of the old one?



##########
apisix/plugins/ldap-auth.lua:
##########
@@ -66,23 +67,27 @@ function _M.check_schema(conf, schema_type)
     return ok, err
 end
 
-local function extract_auth_header(authorization)
+local function extract_auth_header(auth)
     local obj = { username = "", password = "" }
+    -- Check format of Authorization header.
+    local matches, err = ngx_re.split(auth, "\\s+", nil, nil, 2)
 
-    local m, err = ngx.re.match(authorization, "Basic\\s(.+)", "jo")

Review Comment:
   Why not use regex to do the pattern matching and data extraction directly?
   `Basic` is short, and in the worst case we only need to assert the uppercase and lowercase format of each letter.
   There doesn't seem to be a significant means from using split.
   
   `[Bb][Aa][Ss][Ii][Cc]\\s(.*)`
   `(?i:basic)\\s(.*)`



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


Re: [PR] fix: basic auth scheme supports case insensitivity [apisix]

Posted by "SkyeYoung (via GitHub)" <gi...@apache.org>.
SkyeYoung commented on code in PR #12539:
URL: https://github.com/apache/apisix/pull/12539#discussion_r2292371968


##########
t/plugin/basic-auth.t:
##########
@@ -252,7 +288,7 @@ GET /t
 
 
 
-=== TEST 13: invalid schema, not field given
+=== TEST 16: invalid schema, not field given

Review Comment:
   The reason I did this was to put similar test cases together. 🤔 



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


Re: [PR] fix: basic auth scheme supports case insensitivity [apisix]

Posted by "moonming (via GitHub)" <gi...@apache.org>.
moonming commented on PR #12539:
URL: https://github.com/apache/apisix/pull/12539#issuecomment-3216956229

   Totally agree with @bzp2010 


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


Re: [PR] fix: basic auth scheme supports case insensitivity [apisix]

Posted by "Baoyuantop (via GitHub)" <gi...@apache.org>.
Baoyuantop merged PR #12539:
URL: https://github.com/apache/apisix/pull/12539


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


Re: [PR] fix: basic auth scheme supports case insensitivity [apisix]

Posted by "SkyeYoung (via GitHub)" <gi...@apache.org>.
SkyeYoung commented on code in PR #12539:
URL: https://github.com/apache/apisix/pull/12539#discussion_r2297399507


##########
t/plugin/basic-auth.t:
##########
@@ -252,7 +288,7 @@ GET /t
 
 
 
-=== TEST 13: invalid schema, not field given
+=== TEST 16: invalid schema, not field given

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