Skip to content

Field Level Permissions - Users-Permissions - Discussion #2161

@NickBolles

Description

@NickBolles

Edited by @derrickmehaffy on 2021/0329

I have morphed this feature request to point at the Users-Permissions specifically to support Field level permissions.


Summary

This feature request is for permissions on fields.

Currrently

Currently we have permissions on controller actions by roles. This is good for completely restricting access to certain actions, but there are some big issues with it, especially when paired with Graphql.

Background

We stumbled across this issue with the me() query that I created in #2116. Essentially the UserPermissionsUser GraphQL type exposed the UserPermissionsRole type, which itself exposed the Users array of all users with that role. This would allow access to all of the users with the same role. This is a fairly serious exposure of information if steps aren't taken to mitigate it.

I solved this instance with a custom return type UserPermissionsMe and UserPermissionsMeRole that doesn't have Users on it. But that shouldn't have to be done for every type. Also, this UserPermissionsMe type doesn't get updated with any of the fields that are added to UserPermissionsUser, so currently I have to do separate requests for more fields on the users object.

Huge thank you @kamalbennani and @danielmahon for helping me identify and fix these issues!

Potential Solution?

First off, I'm pretty new to Strapi, so this is just my initial take, and by no means a definitive solution. Please give feedback and suggestions!

I think the best way to solve this issue, other issues, and while adding a bunch of functionality and flexibility, is to expand on the permissions plugin to add field level permissions. I am approaching the field permissions similar to the policy field on the permissions model.

I think there are a few parts to it...

1. Config

I see this as an additional section on the permissions edit page in the Advanced Settings section after you've allowed access to an action. This section could list out the fields and have check marks for what is accessible.

2. Storage

These field permissions could be an array on the permissions model. I think just an array of objects with a field property, and an allow property, at least for now.

3. Enforcement

I think the biggest issue comes down to how to enforce these field level permissions. My initial impression is whenever something is returned by a controller, we run it through a processor for the permissions to omit any fields before returning it to the caller.

It seems like almost everything goes through a controller, so this would be a pretty central change, and help to be consistent.

3b. GraphQL

For GraphQL I think we would need another layer, or if not, it might be helpful.

GraphQL Directives are almost exactly what this is for, and could be a standard directive for every field/type.

Bonus Ideas

Owner concept

Making a owner concept would be really neat. Basically this would apply to any model that has a user on it. If the user ID on the model matches the authenticated user, you would have access to that document, very similar to the me query. Of course we'd have to allow this to be turned off. And I'm not quite sure how this would work, But I think it would be very cool to just say, give me all of my stuff.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions