From bc8a875df1609728f1c7674abef46c01168a0d20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20M=C3=A5rtenson?= Date: Tue, 22 Oct 2013 15:55:44 +0800 Subject: [PATCH] When looking up a user by DN, use single scope The blocked? method is used to check whether a user exists in LDAP. Prior to this change, if the LDAP server had more objects below the one pointed to by the DN, those objects would also be picked up by the search, causing the method to determine the user should be blocked. One case where this can happen is when using Active Directory and a user have a mobile phone assigned. In this case, Exchange will add an entry called ExchangeActiveSyncDevices under the users entry. The user-visible behaviour is then that a user loses Gitlab access when he enables a mobile device. This fix sets the search scope to BaseObject in order to ensure that only the user itself is returned. --- lib/gitlab/ldap/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gitlab/ldap/user.rb b/lib/gitlab/ldap/user.rb index 78fc5dab9cb..3d57f3a2e35 100644 --- a/lib/gitlab/ldap/user.rb +++ b/lib/gitlab/ldap/user.rb @@ -78,7 +78,7 @@ module Gitlab # * when ldap account was deactivated by change of OU membership in 'dn' def blocked?(dn) ldap = OmniAuth::LDAP::Adaptor.new(ldap_conf) - ldap.connection.search(base: dn, size: 1).blank? + ldap.connection.search(base: dn, scope: Net::LDAP::SearchScope_BaseObject, size: 1).blank? end private