diff options
author | Louis <6653109+artonge@users.noreply.github.com> | 2021-12-30 11:03:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-30 11:03:30 +0100 |
commit | 4fde409901b96434bc587289372348e0759b3737 (patch) | |
tree | eea955156caa539805917b76021186c1f18f0f9c | |
parent | 43006f2ed9cad02e80406a5c492d8736e710e6ad (diff) | |
parent | 47c916d77a9724e4609ccc68ae4057a18bb5b76c (diff) | |
download | nextcloud-server-4fde409901b96434bc587289372348e0759b3737.tar.gz nextcloud-server-4fde409901b96434bc587289372348e0759b3737.zip |
Merge pull request #30341 from nextcloud/backport/29329/stable21
[stable21] fix potential unwarranted memberships in nested groups from LDAP
-rw-r--r-- | apps/user_ldap/lib/Group_LDAP.php | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/apps/user_ldap/lib/Group_LDAP.php b/apps/user_ldap/lib/Group_LDAP.php index a1ceeffba58..8bf13ed90fd 100644 --- a/apps/user_ldap/lib/Group_LDAP.php +++ b/apps/user_ldap/lib/Group_LDAP.php @@ -249,7 +249,12 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I // but not included in the results laters on $excludeFromResult = $dnGroup; } + // cache only base groups, otherwise groups get additional unwarranted members + $shouldCacheResult = count($seen) === 0; + + static $rawMemberReads = []; // runtime cache for intermediate ldap read results $allMembers = []; + if (array_key_exists($dnGroup, $seen)) { return []; } @@ -291,7 +296,11 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I } $seen[$dnGroup] = 1; - $members = $this->access->readAttribute($dnGroup, $this->access->connection->ldapGroupMemberAssocAttr); + $members = $rawMemberReads[$dnGroup] ?? null; + if ($members === null) { + $members = $this->access->readAttribute($dnGroup, $this->access->connection->ldapGroupMemberAssocAttr); + $rawMemberReads[$dnGroup] = $members; + } if (is_array($members)) { $fetcher = function ($memberDN) use (&$seen) { return $this->_groupMembers($memberDN, $seen); @@ -307,7 +316,10 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I } } - $this->access->connection->writeToCache($cacheKey, $allMembers); + if ($shouldCacheResult) { + $this->access->connection->writeToCache($cacheKey, $allMembers); + unset($rawMemberReads[$dnGroup]); + } if (isset($attemptedLdapMatchingRuleInChain) && $this->access->connection->ldapMatchingRuleInChainState === Configuration::LDAP_SERVER_FEATURE_UNKNOWN && !empty($allMembers) |