Skip to content

fix: system address book card restriction - #63392

Merged
SebastianKrupinski merged 1 commit into
masterfrom
fix/system-address-book
Nov 12, 2026
Merged

SebastianKrupinski merged 1 commit into
masterfrom
fix/system-address-book

Conversation

@SebastianKrupinski

@SebastianKrupinski SebastianKrupinski commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • added logic to the system address book to only enumerate users from a users group

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@SebastianKrupinski

Copy link
Copy Markdown
Contributor Author

/backport to stable34

@SebastianKrupinski

Copy link
Copy Markdown
Contributor Author

/backport to stable33

@SebastianKrupinski

Copy link
Copy Markdown
Contributor Author

/backport to stable32

@nextcloud-bot nextcloud-bot mentioned this pull request Aug 20, 2026
@skjnldsv skjnldsv mentioned this pull request Aug 25, 2026
@SebastianKrupinski
SebastianKrupinski requested a review from a team as a code owner August 31, 2026 19:18
@SebastianKrupinski
SebastianKrupinski requested review from Altahrim, icewind1991, leftybournes and salmart-dev and removed request for a team August 31, 2026 19:18
@joshtrichards joshtrichards added bug feature: carddav Related to CardDAV internals labels Sep 1, 2026
if (!is_array($excludedGroupIds) || $excludedGroupIds === []) {
return false;
}
return array_intersect($this->groupManager->getUserGroupIds($user), $excludedGroupIds) !== [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: the logic here and a similar precedent one in ContactsController is applying the group exclusion in a completely different way than the setting itself advertises: in all other places groups are removed from the user's group list so that the checks about group membership only act on groups that are not in the exclude list.
I guess a common use-case is to have "everyone" groups, but exclude them from counting when checking for group membership and keep the filtering working. With the logic above and the configuration I mentioned, everyone would see everyone else.

Is this the desired outcome?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! Sorry, just saw your comment.

You are correct, I copied the logic from calendar, and it was broken in calendar.

Fixing now

@SebastianKrupinski

This comment was marked as resolved.

@DerDreschner

Copy link
Copy Markdown
Member

/backport to stable35

@SebastianKrupinski

Copy link
Copy Markdown
Contributor Author

@ChristophWurst @kesselb @hamza221 +1 please

@kesselb

kesselb commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Looking at #63392 with #65812 in mind, I think we should extract the enumeration settings to a own helper in this PR.

class SystemAddressbookAccess {
	public function __construct(
		private IShareManager $shareManager,
		private IGroupManager $groupManager,
	) {
	}

	/** @return list<string>|null group IDs whose members $viewer may see, [] for own card only, null if unrestricted */
	private function getVisibleGroupIds(IUser $viewer): ?array {
		if ($viewer->getBackendClassName() === 'Guests'
			|| !$this->shareManager->allowEnumeration()
			|| ($this->shareManager->limitEnumerationToPhone() && !$this->shareManager->limitEnumerationToGroups())) {
			return [];
		}
		if (!$this->shareManager->limitEnumerationToGroups() && !$this->shareManager->shareWithGroupMembersOnly()) {
			return null;
		}
		return array_values(array_diff(
			$this->groupManager->getUserGroupIds($viewer),
			$this->shareManager->shareWithGroupMembersOnlyExcludeGroupsList(),
		));
	}

	public function canSee(IUser $viewer, IUser $target): bool { /* own → true, guest target → false, null → true, else group intersect */ }

	/** @return list<string>|null */
	public function getVisibleCardUris(IUser $viewer): ?array { /* own + non-guest members of getVisibleGroupIds() */ }
}

@kesselb

kesselb commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Federation

  • Trusted-server sync breaks with "only share with group members" (SystemAddressbook.php:117, :166)
    Trusted servers authenticate through FedAuth (apps/federation/lib/DAV/FedAuth.php), which sets no session user. The new || $restrictToOwnGroups branch runs before isFederation(). With a null user it throws Forbidden in getChild() and returns [] in getMultipleChildren(). getChanges() then moves every added or modified URI to deleted, so the remote server drops all federated contacts.
    The enumeration restrictions already behave like this, but this setting is far more common. Suggestion: handle the federation request before the restriction branches, and add a test for federation with the setting enabled.

Config

  • Use the IShareManager helpers instead of reading the keys (SystemAddressbook.php:61-64, :100-103, :155-158, :276)
    IShareManager already has allowEnumeration(), limitEnumerationToGroups(), limitEnumerationToPhone(), shareWithGroupMembersOnly() and shareWithGroupMembersOnlyExcludeGroupsList(). The last one already returns [] when the restriction is off, so the $ignoreExcludedGroups parameter isn't needed.
    This also avoids an AppConfigTypeConflictException: getValueBool()/getValueString() throw if a key was stored with a different explicit type (e.g. occ config:app:set ... --type=string), and the system address book would return 500. These keys aren't in the core lexicon, UserPlugin reads them as strings, and the share manager reads them through getAppValue() without type checks.

Performance

  • getChild() loads every member of every group to check one card (SystemAddressbook.php:171)
    The old loop returned on the first match. Now a user in a 20k-member group causes 20k IUser objects and getCardUri() calls on every single-card GET. Resolving the target from the URI (Backend:uid.vcf) and intersecting getUserGroupIds(), as ContactsStore does, costs O(groups) instead.
  • getMultipleChildren() enumerates all group members to keep a few paths (SystemAddressbook.php:122)
    A multiget for 5 cards loads every member of every group the user is in. Checking only the requested paths makes the cost depend on the request size instead of the group size.

Structure

  • Rule reads copied into three methods (SystemAddressbook.php:61, :100, :155)
    The same four reads appear in getChildren(), getMultipleChildren() and getChild(), and every test re-mocks exactly(4) calls. One decision method would remove the triplication. fix(contactsinteraction): skip recent contacts visible in system addr… #65812 needs the same rule in contactsinteraction, so this could become a small service in dav that both PRs use:
  • Naming of getCardsForUsersGroups() (SystemAddressbook.php:273)
    $ignoreExcludedGroups = true actually turns the exclude list on, so it reads backwards. The method also returns card URIs, not cards.

Housekeeping

  • Commit subject has no scope
    fix: system address book card restriction could be fix(dav): restrict system address book to own groups.

@hamza221
hamza221 marked this pull request as draft November 4, 2026 17:40
@SebastianKrupinski
SebastianKrupinski force-pushed the fix/system-address-book branch 3 times, most recently from 2f8409d to e4656ae Compare November 4, 2026 23:45
@SebastianKrupinski
SebastianKrupinski marked this pull request as ready for review November 4, 2026 23:46
@SebastianKrupinski

Copy link
Copy Markdown
Contributor Author

@kesselb

Please have another look.

$shareEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
$shareEnumerationGroup = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes';
$shareEnumerationPhone = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes';
// Trusted servers have no session user and are not subject to the user restrictions

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ? this is not how it used to work?
I would assume if enumeration is applied to local users it should not sync with remote servers either

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a system address book (a user directory) and the federation process has no user session (system to system) so how do you apply restrictions? We should need to add a UI to select which groups to federate

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't share anything I guess
At least that's how it used to work before the patch no?

@hamza221 hamza221 Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least it should be discussed and not committed as a fix

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree which is why I haven't merged it yet

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "federated groups" don't exist yet, hence it's not possible that a local and remote user are in the same group. If that option is enabled no cards should be synced.

@hamza221

Copy link
Copy Markdown
Contributor

ci fix ab04f59 , rebasing

Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
@hamza221
hamza221 force-pushed the fix/system-address-book branch from 86243b7 to a9389fd Compare November 11, 2026 13:12
@SebastianKrupinski
SebastianKrupinski merged commit 3ecd173 into master Nov 12, 2026
177 of 181 checks passed
@SebastianKrupinski
SebastianKrupinski deleted the fix/system-address-book branch November 12, 2026 00:30
@github-project-automation github-project-automation Bot moved this from 🏗️ In progress to ☑️ Done in 💌 📅 👥 Groupware team Nov 12, 2026
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

3. to review Waiting for reviews bug feature: carddav Related to CardDAV internals

Projects

Status: ☑️ Done

Development

Successfully merging this pull request may close these issues.

7 participants