Skip to content

fix(ldap-auth): key the consumer lookup on the escaped bind DN - #13805

Open
shreemaan-abhishek wants to merge 2 commits into
apache:masterfrom
shreemaan-abhishek:fix/ldap-auth-consumer-dn-escaping
Open

fix(ldap-auth): key the consumer lookup on the escaped bind DN#13805
shreemaan-abhishek wants to merge 2 commits into
apache:masterfrom
shreemaan-abhishek:fix/ldap-auth-consumer-dn-escaping

Conversation

@shreemaan-abhishek

Copy link
Copy Markdown
Contributor

Description

ldap_authenticate() returns the bind DN it assembled as its third value, with the username escaped per RFC 4514 §2.4. The plugin discarded that value and rebuilt the same string by raw concatenation:

local user_dn = conf.uid .. "=" .. user.username .. "," .. conf.base_dn

The two forms diverge as soon as the username carries a character that has structural meaning in a distinguished name (, + = < > ; " \). An entry whose RDN value holds a comma binds against cn=comma\,user,ou=users,dc=example,dc=org, a single RDN, and is then looked up under cn=comma,user,ou=users,dc=example,dc=org, a two-component path. So the request either matches no consumer or matches one that belongs to a different directory entry.

This PR uses the DN the client already produced instead of rebuilding it, which keeps the bind target and the consumer key the same string by construction.

Backward compatibility: a consumer whose user_dn was written in the unescaped form to match the previous behaviour stops matching. This only affects directory entries whose RDN value contains one of the characters above, and the doc note added here spells out the escaped form to use. Every DN without those characters is unchanged.

Tests: the CI directory fixture gains an entry whose cn value is comma,user. Two cases assert that a consumer keyed on the escaped DN matches and one keyed on the raw expansion does not.

Which issue(s) this PR fixes:

Fixes #

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)

ldap_authenticate already returns the bind DN with the username escaped per
RFC 4514. The plugin discarded it and rebuilt the same string by raw
concatenation, so an entry whose RDN value carries a DN delimiter bound
against one DN and was looked up under another.
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant