Skip to content

fix(basic-auth): reject empty consumer password and fail closed - #13883

Closed
waterWang wants to merge 1 commit into
apache:masterfrom
waterWang:fix/basic-auth-empty-password
Closed

fix(basic-auth): reject empty consumer password and fail closed#13883
waterWang wants to merge 1 commit into
apache:masterfrom
waterWang:fix/basic-auth-empty-password

Conversation

@waterWang

Copy link
Copy Markdown

Summary

Fixes #13881basic-auth currently accepts a consumer with an empty password, allowing passwordless access.

RFC 8265 section 4.1 (the OpaqueString password profile referenced by RFC 7617) requires a password to be non-zero-length. Today the Admin API accepts password: "" because consumer_schema.password is declared as plain { type = "string" } with no minLength. Such a consumer authenticates, so it looks protected while it effectively has no secret. Once #13836 lands (split on the first colon per RFC 7617), user: would also return 200 for such a consumer.

Changes

  • apisix/plugins/basic-auth.lua

    • 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. This also covers existing empty-password consumers and $secret:// / $ENV:// references that resolve to "".
  • t/plugin/basic-auth.t — regression tests:

    • consumer schema rejects an empty password
    • Admin API rejects a consumer with an empty password (400)
    • foo: (empty password) returns 401
    • whitespace-only password (foo: ) returns 401

Compatibility with #13836

This change is orthogonal to #13836 (which fixes parsing to split on the first colon). With or without #13836, an empty/whitespace-only password now fails closed with a 401.

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Aug 26, 2026
@waterWang waterWang changed the title fix(basic-auth): reject empty consumer password and fail closed [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT] fix(basic-auth): reject empty consumer password and fail closed Aug 26, 2026
@waterWang
waterWang force-pushed the fix/basic-auth-empty-password branch from 91e1533 to d0b6727 Compare August 26, 2026 08:06
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels 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
@juzhiyuan juzhiyuan closed this Aug 27, 2026
@juzhiyuan

Copy link
Copy Markdown
Member

Thanks but this issue has been fixed by another PR :)

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 accepts an empty consumer password, which allows passwordless access

2 participants