Skip to content

fix(basic-auth): split credentials on the first colon only - #13836

Open
Arjen10 wants to merge 6 commits into
apache:masterfrom
Arjen10:fix/basic-auth-password-colon
Open

fix(basic-auth): split credentials on the first colon only#13836
Arjen10 wants to merge 6 commits into
apache:masterfrom
Arjen10:fix/basic-auth-password-colon

Conversation

@Arjen10

@Arjen10 Arjen10 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Description

RFC 7617 treats everything after the first ':' as the password. ngx.re.split on all colons truncated passwords that contained ':'.

Align with the implementation of ldap-auth-advanced

Which issue(s) this PR fixes:

Fixes #13835

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

RFC 7617 treats everything after the first ':' as the password.
ngx.re.split on all colons truncated passwords that contained ':'.
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Aug 17, 2026
nic-6443
nic-6443 previously approved these changes Aug 26, 2026
membphis
membphis previously approved these changes Aug 26, 2026
AlinsRan
AlinsRan previously approved these changes Aug 26, 2026
waterWang added a commit to waterWang/apisix that referenced this pull request Aug 26, 2026
RFC 8265 section 4.1 requires the OpaqueString password profile to be
non-zero-length. The consumer schema currently declares `password` as plain
`{ type = "string" }` with no minLength, so the Admin API accepts a consumer
whose password is an empty string. Such a consumer authenticates, appearing
protected while effectively having no secret. Once apache#13836 lands (split on the
first colon per RFC 7617), `user:` would also return 200 for an empty-password
consumer.

Fix:
- add `minLength = 1` to `consumer_schema.password` so the Admin API rejects
  empty passwords on consumer create/update
- fail closed in `find_consumer` when either the presented or the resolved
  password is empty, covering legacy empty-password consumers and
  `$secret://` / `$ENV://` references that resolve to ""

Regression tests: consumer schema rejects empty password, Admin API rejects
empty consumer password, empty/whitespace-only passwords in the
Authorization header return 401.

Closes apache#13881
@janiussyafiq

Copy link
Copy Markdown
Contributor

@Arjen10 could u please resolve the merge conflicts, thanks

@Arjen10
Arjen10 dismissed stale reviews from AlinsRan, membphis, and nic-6443 via 1bb0c97 August 27, 2026 08:45
@Arjen10

Arjen10 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

@Arjen10 could u please resolve the merge conflicts, thanks

done

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Aug 27, 2026
nic-6443
nic-6443 previously approved these changes Aug 28, 2026
AlinsRan
AlinsRan previously approved these changes Aug 28, 2026
membphis
membphis previously approved these changes Aug 28, 2026

@membphis membphis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@janiussyafiq

Copy link
Copy Markdown
Contributor

@Arjen10 please fix CI

@Arjen10

Arjen10 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

@Arjen10 please fix CI

ok,i will fix it this weekend

@Arjen10
Arjen10 dismissed stale reviews from membphis, AlinsRan, and nic-6443 via 9e8d437 August 28, 2026 10:15
@Arjen10

Arjen10 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

@janiussyafiq TEST 37–39 set consumer foo's password to $env://BASIC_AUTH_EMPTY_PASSWORD and declare the empty env in nginx main_config.
since etcd is shared by the whole .t file, the next nginx restart no longer declares this env, causing $env:// parsing to log an [error] and later tests to fail.
so TEST 39 changes foo's password back to bar before the env is removed, clearing the secret reference from etcd and keeping subsequent test env clean.

i tested it successfully in my local docker env.

@Arjen10

Arjen10 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

@juzhiyuan please restart github CI

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:L This PR changes 100-499 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

5 participants