fix: remove caching in fetchListOfGroups

When using nested groups without a memberof overlay, then fetchListOfGroups is called from getGroupsByMember without applying the group filter.

In some setups, the "unfiltered" result is then written back to the group mapping table. That might cause random "An administrator removed you from group" activities.

I was unable to replicate it locally, but we got the feedback that the random activities stopped with the patch applied.

Ref: https://github.com/nextcloud/server/issues/42195

Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
pull/47513/head
Daniel Kesselberg 2024-08-27 11:31:54 +07:00 committed by Côme Chilliet
parent 299a62b54d
commit 7facae6b83
No known key found for this signature in database
GPG Key ID: A3E2F658B28C760A
2 changed files with 1 additions and 17 deletions

@ -958,22 +958,6 @@ class Access extends LDAPUtility {
}
$groupRecords = $this->searchGroups($filter, $attr, $limit, $offset);
$listOfDNs = array_reduce($groupRecords, function ($listOfDNs, $entry) {
$listOfDNs[] = $entry['dn'][0];
return $listOfDNs;
}, []);
$idsByDn = $this->getGroupMapper()->getListOfIdsByDn($listOfDNs);
array_walk($groupRecords, function (array $record) use ($idsByDn): void {
$newlyMapped = false;
$gid = $idsByDn[$record['dn'][0]] ?? null;
if ($gid === null) {
$gid = $this->dn2ocname($record['dn'][0], null, false, $newlyMapped, $record);
}
if (!$newlyMapped && is_string($gid)) {
$this->cacheGroupExists($gid);
}
});
$listOfGroups = $this->fetchList($groupRecords, $this->manyAttributes($attr));
$this->connection->writeToCache($cacheKey, $listOfGroups);
return $listOfGroups;

@ -667,7 +667,7 @@ class AccessTest extends TestCase {
$this->groupMapper->expects($this->never())
->method('getNameByDN');
$this->connection->expects($this->exactly(3))
$this->connection->expects($this->exactly(1))
->method('writeToCache');
$groups = $this->access->fetchListOfGroups($filter, $attributes);