Validate LDAP_ENTRY_DN is within configured usersDn in searchLDAPByAt… - #51502
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Prevents LDAP searches from accessing or importing users outside the configured usersDn boundary.
Changes:
- Validates
LDAP_ENTRY_DNbefore LDAP queries. - Adds regression coverage for out-of-scope DN searches.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPStorageProvider.java |
Enforces the configured LDAP user boundary. |
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/LDAPSearchForUsersPaginationTest.java |
Tests rejection through provider and Admin API paths. |
sguilhen
force-pushed
the
51472-ldap-entry-dn-boundary
branch
from
August 6, 2026 19:17
7399d14 to
a722f57
Compare
pedroigor
approved these changes
Aug 10, 2026
…tributes Closes keycloak#51472 Closes CVE-2026-16071 Signed-off-by: Stefan Guilhen <sguilhen@redhat.com>
pedroigor
force-pushed
the
51472-ldap-entry-dn-boundary
branch
from
August 10, 2026 16:07
a722f57 to
7281839
Compare
pedroigor
enabled auto-merge (rebase)
August 10, 2026 16:07
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/LDAPSearchForUsersPaginationTest.java:235
- Stripping quotes via
.replace("\"", "")is brittle (it can also alter legitimate DN contents if quotes appear, and it hides the actual contract offetchString). Prefer returning a non-JSON-encoded value from the server helper (or using a helper that returns a raw string/structured response) so the test doesn’t need ad-hoc unquoting.
String outOfScopeDn = testingClient.server().fetchString(session -> {
LDAPTestContext ctx = LDAPTestContext.init(session);
LDAPStorageProvider ldapProvider = ctx.getLdapProvider();
LDAPTestUtils.addLdapOUinBaseDn(ldapProvider, "ServiceAccounts");
LDAPObject ldapObject = new LDAPObject();
ldapObject.setRdnAttributeName(ldapProvider.getLdapIdentityStore().getConfig().getRdnLdapAttribute());
ldapObject.setObjectClasses(ldapProvider.getLdapIdentityStore().getConfig().getUserObjectClasses());
ldapObject.setSingleAttribute(ldapProvider.getLdapIdentityStore().getConfig().getRdnLdapAttribute(), "outsideuser");
ldapObject.setSingleAttribute(LDAPConstants.SN, "Outside");
ldapObject.setSingleAttribute(LDAPConstants.CN, "outsideuser");
ldapObject.setSingleAttribute(LDAPConstants.GIVENNAME, "Outside");
ldapObject.setSingleAttribute("mail", "outsideuser@example.org");
LDAPDn dn = LDAPDn.fromString(ldapProvider.getLdapIdentityStore().getConfig().getBaseDn());
dn.addFirst("ou", "ServiceAccounts");
dn.addFirst(ldapProvider.getLdapIdentityStore().getConfig().getRdnLdapAttribute(), "outsideuser");
ldapObject.setDn(dn);
ldapProvider.getLdapIdentityStore().add(ldapObject);
// verify the entry exists in LDAP.
try (LDAPQuery ldapQuery = LDAPUtils.createQueryForUserSearch(ldapProvider, ctx.getRealm())) {
ldapQuery.setSearchDn(dn.toString());
ldapQuery.setSearchScope(SearchControls.OBJECT_SCOPE);
Assertions.assertNotNull(ldapQuery.getFirstResult(), "Out-of-scope LDAP entry should exist");
}
return dn.toString();
}).replace("\"", "");
Comment on lines
+562
to
+567
| LDAPDn entryDn = LDAPDn.fromString(entry.getValue()); | ||
| LDAPDn usersDn = LDAPDn.fromString(ldapIdentityStore.getConfig().getUsersDn()); | ||
| if (!entryDn.isDescendantOf(usersDn)) { | ||
| logger.debugf("LDAP_ENTRY_DN [%s] is not within configured usersDn [%s], returning empty stream", entry.getValue(), ldapIdentityStore.getConfig().getUsersDn()); | ||
| return Stream.empty(); | ||
| } |
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.
…tributes
Closes #51472
Closes CVE-2026-16071