[2.x] fix: scope UserResource groups relationship to viewable groups#4629
Merged
Conversation
The groups ToMany relationship on UserResource resolved against User::groups() unfiltered, so relationships.groups.data leaked hidden group IDs to actors without viewHiddenGroups — even though GroupResource::scope() filtered out the hidden groups themselves from the included resources. Add a get() callback that returns User::visibleGroups() for actors without viewHiddenGroups, mirroring the visibility check used by ScopeGroupVisibility. Fixes #4618
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GET /api/users/{id}was including hidden group IDs indata.relationships.groups.datafor actors without theviewHiddenGroupspermission.The
groupsToManyrelationship onUserResourceresolved against the unfilteredUser::groups()Eloquent relation, so linkage leaked hidden group IDs even thoughGroupResource::scope()correctly filtered the hidden groups themselves out of theincludedresources. The frontend store (andUser.badges()rendering) therefore received hidden group references it shouldn't have known about.Adds a
get()callback on the relationship that returnsUser::visibleGroups()(which already excludesis_hidden = 1) for actors withoutviewHiddenGroups, mirroring the visibility check inGroup\Access\ScopeGroupVisibility.Fixes #4618
Changes
framework/core/src/Api/Resource/UserResource.php— add->get(...)to thegroupsrelationship that branches on$context->getActor()->can('viewHiddenGroups').framework/core/tests/integration/api/users/ShowGroupsRelationshipTest.phpcovering guest, normal user, and admin actors against/api/users/{id}.Test plan
ShowGroupsRelationshipTestpasses (3 tests, 9 assertions)./api/users/{id}as guest / non-privileged member — confirmrelationships.groups.dataonly contains visible group IDs.Notes
relationships.groups.datawere already broken on the hidden-groups case (the included resources weren't there); now the linkage matches the included resources.UpdateandIndexendpoints (bothdefaultInclude(['groups'])), so the fix applies there too.