Skip to content

[4.4.x] Escape %u/%dn/%fqdn substitutions in LDAP search filters - #2881

Merged
jbonofre merged 1 commit into
apache:karaf-4.4.xfrom
jbonofre:backport/2880-ldap-filter-injection-4.4.x
Sep 11, 2026
Merged

[4.4.x] Escape %u/%dn/%fqdn substitutions in LDAP search filters#2881
jbonofre merged 1 commit into
apache:karaf-4.4.xfrom
jbonofre:backport/2880-ldap-filter-injection-4.4.x

Conversation

@jbonofre

Copy link
Copy Markdown
Member

Summary

Backport of #2880 to karaf-4.4.x.

  • LDAPCache and LDAPBackingEngine.lookupUser built LDAP search filters by substituting %u/%dn/%fqdn and only doubling backslashes, which does not escape *, (, ), or NUL. A username containing filter metacharacters (e.g. *) could widen a search filter to match an unintended directory entry instead of failing lookup, and could similarly widen role-search filters.
  • LDAPLoginModule/LDAPPubkeyLoginModule masked this for their own callers by pre-escaping the username before it reached the cache, but GSSAPILdapLoginModule and LDAPBackingEngine.lookupUser did not escape at all.
  • This centralizes proper RFC 4515 filter escaping (via the existing Util.doRFC2254Encoding helper) at the point filters are actually built in LDAPCache/LDAPBackingEngine, and removes the now-redundant pre-escaping in LDAPLoginModule/LDAPPubkeyLoginModule so escaping happens exactly once. GSSAPILdapLoginModule needed no change since it now goes through the fixed LDAPCache path.

Cherry-picked cleanly from main, no conflicts.

Test plan

  • Added LdapCacheTest.testUserFilterInjectionDoesNotWidenSearch and testBackingEngineUserFilterInjectionDoesNotWidenSearch, which call LDAPCache.getUserDnAndNamespace("*") / LDAPBackingEngine.lookupUser("*") and assert no match.
  • Verified both new tests fail against the pre-fix code (a "*" username matched an unrelated real user) and pass with the fix.
  • Full existing LDAP JAAS test suite (LdapLoginModuleTest, LdapLoginModuleWithEscapesTest, LdapCacheTest, LDAPPubkeyLoginModuleTest, GSSAPILdapLoginModuleTest, LdapCaseInsensitiveDNTest, LdapPoolingTest, LdapSpecialCharsInPasswordTest) passes on karaf-4.4.x, including the DN-special-character and %fqdn role-mapping tests.

LDAPCache and LDAPBackingEngine.lookupUser built search filters by
substituting %u/%dn/%fqdn and only doubling backslashes, which does not
escape *, (, ), or NUL. LDAPLoginModule and LDAPPubkeyLoginModule masked
this by pre-escaping the username themselves, but GSSAPILdapLoginModule
and LDAPBackingEngine.lookupUser did not, so filter metacharacters in a
login name could widen a search (e.g. a username of "*" matches any
entry) and potentially over-grant roles.

Centralize proper RFC 4515 filter escaping in LDAPCache/LDAPBackingEngine
using the existing Util.doRFC2254Encoding helper, and drop the redundant
pre-escaping in LDAPLoginModule/LDAPPubkeyLoginModule so escaping happens
exactly once, at the point filters are built.
@github-actions

Copy link
Copy Markdown

Test Results

  656 files    656 suites   1h 0m 57s ⏱️
1 010 tests   967 ✅  43 💤 0 ❌
2 762 runs  2 642 ✅ 120 💤 0 ❌

Results for commit 3d9881d.

@jbonofre
jbonofre merged commit 8e69e00 into apache:karaf-4.4.x Sep 11, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant