Skip to content

fix(basic-auth): keep colons in password when parsing auth header - #13895

Open
mehrdadbn9 wants to merge 1 commit into
apache:masterfrom
mehrdadbn9:fix/basic-auth-password-with-colon
Open

fix(basic-auth): keep colons in password when parsing auth header#13895
mehrdadbn9 wants to merge 1 commit into
apache:masterfrom
mehrdadbn9:fix/basic-auth-password-with-colon

Conversation

@mehrdadbn9

Copy link
Copy Markdown

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

  • Signed-off (Apache ICLA)
  • Minimal, scoped change
  • No docs change needed

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Aug 28, 2026
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
mehrdadbn9 force-pushed the fix/basic-auth-password-with-colon branch from 987ebd9 to d7fe189 Compare August 28, 2026 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: basic-auth password containing colon is truncated

1 participant