Skip to content

[ldap] Prohibit requests with empty password #10401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ydb/core/security/ldap_auth_provider/ldap_auth_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ class TLdapAuthProvider : public NActors::TActorBootstrapped<TLdapAuthProvider>
+ NKikimrLdap::LdapError(*request.Ld),
.Retryable = false}}};
}
if (request.Password.Empty()) {
NKikimrLdap::MemFree(dn);
return {{TEvLdapAuthProvider::EStatus::UNAUTHORIZED,
{.Message = "LDAP login failed. Empty password",
.Retryable = false}}};
}
TEvLdapAuthProvider::TError error;
int result = NKikimrLdap::Bind(*request.Ld, dn, request.Password);
if (!NKikimrLdap::IsSuccess(result)) {
Expand Down
42 changes: 42 additions & 0 deletions ydb/services/ydb/ydb_ldap_login_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,48 @@ Y_UNIT_TEST_SUITE(TGRpcLdapAuthentication) {
ldapServer.Stop();
}

Y_UNIT_TEST(LdapAuthWithEmptyPassword) {
TString login = "ldapUser";
TString password = "";

LdapMock::TLdapMockResponses responses;
responses.BindResponses.push_back({{{.Login = "cn=robouser,dc=search,dc=yandex,dc=net", .Password = "robouserPassword"}}, {.Status = LdapMock::EStatus::SUCCESS}});

LdapMock::TSearchRequestInfo fetchUserSearchRequestInfo {
{
.BaseDn = "dc=search,dc=yandex,dc=net",
.Scope = 2,
.DerefAliases = 0,
.Filter = {.Type = LdapMock::EFilterType::LDAP_FILTER_EQUALITY, .Attribute = "uid", .Value = login},
.Attributes = {"1.1"}
}
};

std::vector<LdapMock::TSearchEntry> fetchUserSearchResponseEntries {
{
.Dn = "uid=" + login + ",dc=search,dc=yandex,dc=net"
}
};

LdapMock::TSearchResponseInfo fetchUserSearchResponseInfo {
.ResponseEntries = fetchUserSearchResponseEntries,
.ResponseDone = {.Status = LdapMock::EStatus::SUCCESS}
};
responses.SearchResponses.push_back({fetchUserSearchRequestInfo, fetchUserSearchResponseInfo});

TLoginClientConnection loginConnection(InitLdapSettings);
LdapMock::TLdapSimpleServer ldapServer(loginConnection.GetLdapPort(), responses);

auto factory = CreateLoginCredentialsProviderFactory({.User = login + "@ldap", .Password = password});
auto loginProvider = factory->CreateProvider(loginConnection.GetCoreFacility());
TStringBuilder expectedErrorMessage;
expectedErrorMessage << "LDAP login failed. Empty password";
UNIT_ASSERT_EXCEPTION_CONTAINS(loginProvider->GetAuthInfo(), yexception, expectedErrorMessage);

loginConnection.Stop();
ldapServer.Stop();
}

Y_UNIT_TEST(LdapAuthSetIncorrectDomain) {
TString login = "ldapuser";
TString password = "ldapUserPassword";
Expand Down
Loading