[4.4.x] Escape %u/%dn/%fqdn substitutions in LDAP search filters - #2881
Merged
jbonofre merged 1 commit intoSep 11, 2026
Merged
Conversation
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.
Test Results 656 files 656 suites 1h 0m 57s ⏱️ Results for commit 3d9881d. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Backport of #2880 to
karaf-4.4.x.LDAPCacheandLDAPBackingEngine.lookupUserbuilt LDAP search filters by substituting%u/%dn/%fqdnand 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/LDAPPubkeyLoginModulemasked this for their own callers by pre-escaping the username before it reached the cache, butGSSAPILdapLoginModuleandLDAPBackingEngine.lookupUserdid not escape at all.Util.doRFC2254Encodinghelper) at the point filters are actually built inLDAPCache/LDAPBackingEngine, and removes the now-redundant pre-escaping inLDAPLoginModule/LDAPPubkeyLoginModuleso escaping happens exactly once.GSSAPILdapLoginModuleneeded no change since it now goes through the fixedLDAPCachepath.Cherry-picked cleanly from main, no conflicts.
Test plan
LdapCacheTest.testUserFilterInjectionDoesNotWidenSearchandtestBackingEngineUserFilterInjectionDoesNotWidenSearch, which callLDAPCache.getUserDnAndNamespace("*")/LDAPBackingEngine.lookupUser("*")and assert no match."*"username matched an unrelated real user) and pass with the fix.LdapLoginModuleTest,LdapLoginModuleWithEscapesTest,LdapCacheTest,LDAPPubkeyLoginModuleTest,GSSAPILdapLoginModuleTest,LdapCaseInsensitiveDNTest,LdapPoolingTest,LdapSpecialCharsInPasswordTest) passes onkaraf-4.4.x, including the DN-special-character and%fqdnrole-mapping tests.