-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AC-1981] Fix CollectionsController.Get auth check by just checking collections for the requested orgId #3575
Conversation
var assignedCollections = await _collectionRepository.GetManyByUserIdAsync(_currentContext.UserId.Value, FlexibleCollectionsIsEnabled); | ||
orgCollections = assignedCollections.Where(c => c.OrganizationId == orgId).ToList(); | ||
var readAuthorized = (await _authorizationService.AuthorizeAsync(User, orgCollections, BulkCollectionOperations.Read)).Succeeded; | ||
if (!readAuthorized) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think this is problematic. orgCollections
will be all collections the user is assigned to for that org, but not necessarily all they have manage permissions for. So the authorizationService call could still fail.
The idea of this endpoint is "give me all the collections the user is allowed to read". If they can't read all, that basically means just the ones they have manage permissions for. If they don't have any, then it returns an empty ListResponseModel. It should basically never throw.
Therefore I think you just want to do orgCollections = assignedCollections.Where(c => c.OrganizationId == orgId && c.Manage).ToList();
without any further call to AuthorizationService
.
Yes it's unfortunate that this is effectively repeating auth logic that we're trying to centralize in the handler, but handlers don't do filtering. It's breaking the abstraction a little, but I think we gotta.
Tagging @shane-melton as he was in these discussions as well.
If (if!) my suggestions here are correct, I think it would also apply to the other "filtering" endpoint here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds about right. We did have this discussion for this other endpoint here. I went ahead and did those modifications, let me know what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm! Thanks for following up on this
Type of change
Objective
CollectionsController.Get
would throw aNotFoundException
if the user was assigned to collections in multiple organizations.Code changes
Before you submit
dotnet format --verify-no-changes
) (required)