Skip to content

fix: keep numeric user IDs when merging file activity recipients - #3072

Open
motey wants to merge 1 commit into
nextcloud:masterfrom
motey:fix/numeric-uids-cached-mountpoints
Open

motey wants to merge 1 commit into
nextcloud:masterfrom
motey:fix/numeric-uids-cached-mountpoints

Conversation

@motey

@motey motey commented Oct 28, 2026

Copy link
Copy Markdown

Fixes #3071

Problem

FilesHooks keys the recipient lists (uid => path) and the email/notification settings (uid => value) by user ID and combines them with array_merge(). PHP stores numeric string keys like '55' as integers, and array_merge() renumbers integer keys from 0. On instances with numeric user IDs (e.g. user_oidc with a numeric sub):

  • with activity_use_cached_mountpoints=true, file activities (created, changed, deleted, restored, renamed, moved) are written for the users 0, 1, 2, ... instead of the real recipients. If a user with such an ID exists, they receive the activities of shares they have no access to.
  • when someone favorited the file, the settings from the favorite lookup are merged the same way, so the affected users lose their email and notification settings for that activity. This also happens with activity_use_cached_mountpoints=false.

Change

  • Use array_replace() instead of array_merge() for the keyed merges in getFileChangeActivitySettings(), addNotificationsForFileAction(), fileMove(), fileRenaming() and fileMoving(). For string keys the result is the same as before (later values win), integer keys are kept.
  • Cast the user ID to string in the loops of fileRenaming() and generateDelete/Add/MoveActivities(), as addNotificationsForFileAction() already does. Otherwise $user === $this->currentUser->getUID() is never true for numeric IDs and the actor gets renamed_by/moved_by instead of renamed_self/moved_self.

The array_merge() calls on plain lists ($allUsers, $usersToCheck, $rules) are not affected and stay as they are.

Tests

Added to tests/FilesHooksTest.php, all with numeric user IDs (56 is the actor):

  • testAddNotificationsForFileActionNumericUserIds: recipients from the access list, with and without cached mounts, plus a favorite. Checks the user IDs, subjects and email/notification settings passed to addNotificationsForUser().
  • testFileRenamingNumericUserIdsWithMountCache
  • testFileMoveNumericUserIdsWithMountCache: cross-folder move with deleted, added and moved users.

All new tests fail on master (activities go to 0, 1, 2, 3) and pass with this change. The full unit suite passes locally (470 tests, SQLite, server master), and php-cs-fixer and psalm report no issues.

The same code is in stable33, stable34 and stable35, so a backport would help the affected instances.

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI (Claude Opus 5.5, effort high)

User IDs are used as array keys for the recipient lists and the
notification settings. PHP stores numeric string keys like '55' as
integers, and array_merge() renumbers integer keys from 0. With
activity_use_cached_mountpoints enabled, file activities on instances
with numeric user IDs were written for the users 0, 1, 2, ... instead
of the real recipients. The email and notification settings of users
who favorited the file were lost the same way.

Use array_replace() for these keyed merges and cast the keys back to
strings before comparing them with the current user, so the actor gets
the "self" subject on rename and move.

Fixes nextcloud#3071

Signed-off-by: motey <bleimehl@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File activities are delivered to wrong users ("0", "1", "2", ...) when activity_use_cached_mountpoints is enabled and user IDs are numeric

1 participant