Skip to content
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

Respect User enumeration #18683

Closed
wants to merge 3 commits into from
Closed

Conversation

foobarable
Copy link

Respect shareapi_allow_share_dialog_user_enumeration in user_ldap filter
generation function to increase seach performance in sharing dialog.

cc @blizzz @MorrisJobke

Respect shareapi_allow_share_dialog_user_enumeration in user_ldap filter
generation function to increase seach performance in sharing dialog.
@scrutinizer-notifier
Copy link

A new inspection was created.

@foobarable
Copy link
Author

Should also be respected in getAdvancedFilterPartForSearch()

@ghost
Copy link

ghost commented Aug 30, 2015

Thanks a lot for your contribution!
Contributions to the core repo require a signed contributors agreement http://owncloud.org/about/contributor-agreement/

Alternatively you can add a comment here where you state that this contribution is MIT licensed.

Some more details about out pull request workflow can be found here: http://owncloud.org/code-reviews-on-github/

@MorrisJobke
Copy link
Contributor

@blizzz I just discussed with @foobarable the performance of the fix that was introduced with #18353

The question here is if this has effects to the user management search. Any idea how to handle this?

@MorrisJobke
Copy link
Contributor

@owncloud-bot this is okay to test

@blizzz
Copy link
Contributor

blizzz commented Aug 31, 2015

The question here is if this has effects to the user management search. Any idea how to handle this?

I discussed this with @foobarable: Yes, it has impact, when you search for a user on the User page. However, an admin usually knows the user id, so it should not be a problem. Listings without search term work normally.

@blizzz
Copy link
Contributor

blizzz commented Aug 31, 2015

Should also be respected in getAdvancedFilterPartForSearch()

The direct approach is:

diff --git a/apps/user_ldap/lib/access.php b/apps/user_ldap/lib/access.php
index a2eb834..7f928e0 100644
--- a/apps/user_ldap/lib/access.php
+++ b/apps/user_ldap/lib/access.php
@@ -1121,8 +1121,12 @@ class Access extends LDAPUtility implements user\IUserTools {
        }
        $searchWords = explode(' ', trim($search));
        $wordFilters = array();
+       $config = \oc::$server->getConfig();
+       $allowEnum = $config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', false);
        foreach($searchWords as $word) {
-           $word .= '*';
+           if($allowEnum === true) {
+               $word .= '*';
+           }
            //every word needs to appear at least once
            $wordMatchOneAttrFilters = array();
            foreach($searchAttributes as $attr) {

It adds a bit of duplication (getting the config instance, fetching the value, modifying the search termn), this could be summed up in a method of it's own e.g. (prepareSearchTerm($term)) that returns the final search term as done by

$search = empty($search) ? '*' : 
     $allowEnum ? $search . '*' : $search;

The advanced method just calls it for every $word.

@MorrisJobke
Copy link
Contributor

@foobarable Can we get the second change that was proposed by @blizzz in?

@DeepDiver1975 DeepDiver1975 modified the milestones: backlog, 9.0-next Sep 24, 2015
@DeepDiver1975
Copy link
Member

we are beyond feature freeze -> 9.0

@DeepDiver1975
Copy link
Member

@blizzz anything missing? THX

@MorrisJobke
Copy link
Contributor

@foobarable Still open ;) Did you recently found time to fix the remaining stuff?

@jancborchardt
Copy link
Member

@owncloud/ldap can you test this? You can also use this shorthand mention to get your pull requests reviewed. :)

@foobarable
Copy link
Author

@blizzz @MorrisJobke
So you mean like this? I have not testet this yet but can do if you think this is the correct way.
I'll also comment the addition function then.

diff --git a/apps/user_ldap/lib/access.php b/apps/user_ldap/lib/access.php
index 667f107..b3f71a7 100644
--- a/apps/user_ldap/lib/access.php
+++ b/apps/user_ldap/lib/access.php
@@ -1193,7 +1193,7 @@ class Access extends LDAPUtility implements user\IUserTools {
                $searchWords = explode(' ', trim($search));
                $wordFilters = array();
                foreach($searchWords as $word) {
-                       $word .= '*';
+                       $word = $this->prepareSearchTerm($word);
                        //every word needs to appear at least once
                        $wordMatchOneAttrFilters = array();
                        foreach($searchAttributes as $attr) {
@@ -1226,7 +1226,8 @@ class Access extends LDAPUtility implements user\IUserTools {
                                );
                        }
                }
-               $search = empty($search) ? '*' : $search.'*';
+
+               $search = $this->prepareSearchTerm($search);
                if(!is_array($searchAttributes) || count($searchAttributes) === 0) {
                        if(empty($fallbackAttribute)) {
                                return '';
@@ -1243,6 +1244,16 @@ class Access extends LDAPUtility implements user\IUserTools {
                return $this->combineFilterWithOr($filter);
        }

+       private function prepareSearchTerm($term) {
+               $config = \oc::$server->getConfig();
+
+               $allowEnum = $config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', false);
+
+               $term = empty($term) ? '*' :
+                       $allowEnum ? $term . '*' : $term;
+               return $term;
+       }
+
        /**
         * returns the filter used for counting users
         * @return string

@MorrisJobke
Copy link
Contributor

So you mean like this? I

Looks good. Can you please apply the changes? (you don't need to merge in the master branch via github ;))

@blizzz
Copy link
Contributor

blizzz commented Dec 9, 2015

I second @MorrisJobke

@foobarable
Copy link
Author

The patch as i wrote it does not work yet in Version 8.2.1.4 Still trying to find out what's wrong.

@foobarable
Copy link
Author

Created new pull request here: #21324

@foobarable foobarable closed this Dec 22, 2015
@lock lock bot locked as resolved and limited conversation to collaborators Aug 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants