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

   ### Description
   
   Fixes #13835 — RFC 7617 allows colons in credentials, but the basic-auth 
plugin split the decoded `user:password` header on **every** colon. A password 
such as `john:key` was truncated to `john`, so authentication failed.
   
   ### Root cause
   `apisix/plugins/basic-auth.lua` used `ngx_re.split(decoded, ":")` (no 
limit), producing `{"johndoe-colon", "john", "key"}` for 
`johndoe-colon:john:key`. `res[2]` then captured only `john`.
   
   ### Fix
   Split only on the first colon using `ngx_re.split(decoded, ":", nil, nil, 
2)`, so `res[1]` is the username and `res[2]` is the remainder (colons 
included).
   
   Verified with the real OpenResty `ngx.re.split`:
   - buggy (no max): `johndoe-colon:john:key` -> username=`johndoe-colon`, 
password=`john` (truncated)
   - fixed (max=2): `johndoe-colon:john:key` -> username=`johndoe-colon`, 
password=`john:key`
   
   ### Test
   Added `t/plugin/basic-auth.t` TEST 2 exercising a colon-containing password. 
Also exported `extract_auth_header` as `_M.extract_auth_header` so the parsing 
is unit-testable.
   
   ### Checklist
   - [x] Signed-off (Apache ICLA)
   - [x] Minimal, scoped change
   - [x] No docs change needed


-- 
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: [email protected]

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

Reply via email to