Skip to content

fix(basic-auth): reject an empty consumer password - #13884

Merged
nic-6443 merged 3 commits into
apache:masterfrom
janiussyafiq:fix-basic-auth-empty-password
Aug 27, 2026
Merged

fix(basic-auth): reject an empty consumer password#13884
nic-6443 merged 3 commits into
apache:masterfrom
janiussyafiq:fix-basic-auth-empty-password

Conversation

@janiussyafiq

Copy link
Copy Markdown
Contributor

Description

The basic-auth consumer schema accepted password: "", and such a consumer could authenticate with user: on the wire (and with user: once #13836 splits credentials on the first colon).

  • consumer_schema.password now requires minLength = 1, so the Admin API rejects an empty password on consumers and credentials.
  • The plugin fails closed with the usual generic 401 when the resolved password is empty, which also covers data written before this change and $secret:// / $env:// references that resolve to "".
  • Docs: the password attribute is documented as a non-empty string.

Which issue(s) this PR fixes:

Fixes #13881

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)

The consumer schema accepted `password: ""`, and such a consumer could
authenticate with `user: ` (or `user:` once credentials are split on the
first colon). Require a non-empty password in the schema and fail closed
with 401 when the resolved password is empty, which also covers existing
data and secret references that resolve to "".

Fixes apache#13881
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Aug 26, 2026
Comment thread apisix/plugins/basic-auth.lua Outdated
The consumer schema is enforced on write by the Admin API and on load by
plugin_checker, so the runtime empty-password check is redundant. Drop it
together with the secret-reference tests that exercised it.
@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 27, 2026
nic-6443
nic-6443 previously approved these changes Aug 27, 2026
@membphis

Copy link
Copy Markdown
Member

[P1] Reject passwords that resolve to an empty secret or environment value

minLength = 1 only validates the non-empty $secret://... or $env://... reference string. consumer.lua resolves that reference before building the consumer cache, and a resolved empty string is not rejected. basic-auth.lua then compares it directly with the request password, so a Basic header containing the matching username and an empty password can still authenticate when the reference resolves to "".

Please reject an empty password after secret/environment resolution, for example in the basic-auth runtime check or by revalidating the resolved consumer config, and add regressions showing $env:// and $secret:// values resolving to "" return the generic 401 response.

Restore the runtime check dropped in b471cb2: minLength only validates the
$secret:// or $env:// reference string, and consumer.lua resolves it after
validation, so a reference that resolves to "" would otherwise authenticate
`user:`. Add regressions for both $secret:// and $env:// resolving to "".
@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 merged commit a036f18 into apache:master Aug 27, 2026
19 checks passed
@janiussyafiq
janiussyafiq deleted the fix-basic-auth-empty-password branch August 27, 2026 08:19
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 accepts an empty consumer password, which allows passwordless access

4 participants