Skip to content

Commit e1b2021

Browse files
authored
[ldap] Prohibit requests with empty password (#10399)
1 parent d9167c4 commit e1b2021

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

ydb/core/security/ldap_auth_provider/ldap_auth_provider.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ class TLdapAuthProvider : public NActors::TActorBootstrapped<TLdapAuthProvider>
261261
return {{TEvLdapAuthProvider::EStatus::UNAUTHORIZED,
262262
{.Message = ERROR_MESSAGE, .Retryable = false}}};
263263
}
264+
if (request.Password.Empty()) {
265+
LDAP_LOG_D("LDAP login failed for user " << TString(dn) << ". Empty password");
266+
NKikimrLdap::MemFree(dn);
267+
return {{.Status = TEvLdapAuthProvider::EStatus::UNAUTHORIZED, .Error = {.Message = TString(ERROR_MESSAGE) + ". Empty password", .Retryable = false}}};
268+
}
264269
TEvLdapAuthProvider::TError error;
265270
LDAP_LOG_D("bind: bindDn: " << dn);
266271
int result = NKikimrLdap::Bind(*request.Ld, dn, request.Password);

ydb/services/ydb/ydb_ldap_login_ut.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,46 @@ Y_UNIT_TEST_SUITE(TGRpcLdapAuthentication) {
364364
ldapServer.Stop();
365365
}
366366

367+
Y_UNIT_TEST(LdapAuthWithEmptyPassword) {
368+
TString login = "ldapUser";
369+
TString password = "";
370+
371+
LdapMock::TLdapMockResponses responses;
372+
responses.BindResponses.push_back({{{.Login = "cn=robouser,dc=search,dc=yandex,dc=net", .Password = "robouserPassword"}}, {.Status = LdapMock::EStatus::SUCCESS}});
373+
374+
LdapMock::TSearchRequestInfo fetchUserSearchRequestInfo {
375+
{
376+
.BaseDn = "dc=search,dc=yandex,dc=net",
377+
.Scope = 2,
378+
.DerefAliases = 0,
379+
.Filter = {.Type = LdapMock::EFilterType::LDAP_FILTER_EQUALITY, .Attribute = "uid", .Value = login},
380+
.Attributes = {"1.1"}
381+
}
382+
};
383+
384+
std::vector<LdapMock::TSearchEntry> fetchUserSearchResponseEntries {
385+
{
386+
.Dn = "uid=" + login + ",dc=search,dc=yandex,dc=net"
387+
}
388+
};
389+
390+
LdapMock::TSearchResponseInfo fetchUserSearchResponseInfo {
391+
.ResponseEntries = fetchUserSearchResponseEntries,
392+
.ResponseDone = {.Status = LdapMock::EStatus::SUCCESS}
393+
};
394+
responses.SearchResponses.push_back({fetchUserSearchRequestInfo, fetchUserSearchResponseInfo});
395+
396+
TLoginClientConnection loginConnection(InitLdapSettings);
397+
LdapMock::TLdapSimpleServer ldapServer(loginConnection.GetLdapPort(), responses);
398+
399+
auto factory = CreateLoginCredentialsProviderFactory({.User = login + "@ldap", .Password = password});
400+
auto loginProvider = factory->CreateProvider(loginConnection.GetCoreFacility());
401+
UNIT_ASSERT_EXCEPTION_CONTAINS(loginProvider->GetAuthInfo(), yexception, "User is unauthorized in LDAP server. Empty password");
402+
403+
loginConnection.Stop();
404+
ldapServer.Stop();
405+
}
406+
367407
Y_UNIT_TEST(LdapAuthSetIncorrectDomain) {
368408
TString login = "ldapuser";
369409
TString password = "ldapUserPassword";

0 commit comments

Comments
 (0)