fix(basic-auth): keep colons in password when parsing auth header - #13895
Open
mehrdadbn9 wants to merge 1 commit into
Open
fix(basic-auth): keep colons in password when parsing auth header#13895mehrdadbn9 wants to merge 1 commit into
mehrdadbn9 wants to merge 1 commit into
Conversation
RFC 7617 allows colons in credentials. The previous code split the decoded 'user:password' header on every colon, so a password such as 'john:key' was truncated to 'john' and authentication failed. Split only on the first colon so the username is everything before it and the password is the remainder (including any colons). Refs apache#13835 Signed-off-by: Mehrdad Biukian Naeini <mehrdadbiukian@gmail.com>
mehrdadbn9
force-pushed
the
fix/basic-auth-password-with-colon
branch
from
August 28, 2026 06:47
987ebd9 to
d7fe189
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #13835 — RFC 7617 allows colons in credentials, but the basic-auth plugin split the decoded
user:passwordheader on every colon. A password such asjohn:keywas truncated tojohn, so authentication failed.Root cause
apisix/plugins/basic-auth.luausedngx_re.split(decoded, ":")(no limit), producing{"johndoe-colon", "john", "key"}forjohndoe-colon:john:key.res[2]then captured onlyjohn.Fix
Split only on the first colon using
ngx_re.split(decoded, ":", nil, nil, 2), sores[1]is the username andres[2]is the remainder (colons included).Verified with the real OpenResty
ngx.re.split:johndoe-colon:john:key-> username=johndoe-colon, password=john(truncated)johndoe-colon:john:key-> username=johndoe-colon, password=john:keyTest
Added
t/plugin/basic-auth.tTEST 2 exercising a colon-containing password. Also exportedextract_auth_headeras_M.extract_auth_headerso the parsing is unit-testable.Checklist