Replies: 4 comments 2 replies
-
I'll preface this with the fact that I don't have experience with GraphQL or Graphiti. So this will be my generalized approach to authz. Personally, I wouldn't rely solely on scoping for authz, simply because your scope may have a bug in the future that leaks records. It may not now, but it could. When it comes to authz, I like to be as defensive as possible. It's better to catch that and send a 401 than to render records you shouldn't. The controller should scope the models, and the policy should assert that scope. It's safer to have both of those assertions than to only have one. So I typically do both. With eager loading, N+1s aren't a concern. |
Beta Was this translation helpful? Give feedback.
-
@palkan , it will really help us if you share your thoughts on the subject as an original author :) |
Beta Was this translation helpful? Give feedback.
-
Thanks for the question! Scoping-based authorization is a common technique, but I would use it with caution. Especially the following scenario:
Yes, we can. From the first look, having So, I prefer to separate single-record checks from scopes. What would be great is to link rules and scopes, i.e., have a built-in mechanism which verifies that scopes and checks are in sync (i.e., if |
Beta Was this translation helpful? Give feedback.
-
Thanks everyone for your ideas! |
Beta Was this translation helpful? Give feedback.
-
The idea is simple: Action Policy supports scoping (which we gladly use with our Graphiti integration), but don't you think that:
index
action, we will most likely rely only on requesting users's fields. If we take scoping into account (e.g. user is prohibited from listing entities) we can effectively fold his scope into an empty collection thus preventing him from using index action at all (we think that it is not a big deal to return HTTP 200 with an empty collection instead of HTTP 401);show
action, we can rely on scoping again (since it is not so different from anindex
action);verify_authorized
marker. If we only use scoping forindex
andshow
authorization, we'll end up with an authorization error in the end.The idea is simple: is it a suitable use case to treat
index
andshow
actions as authorized (passingverify_authorized
checks) if the scoping was successfully performed?P.S. the idea was born simply because with our Graphiti integration it is much harder to try to authorize
index
actions (we moved the authorization to resources (model proxies) from controllers since you can side-post multiple entities in the same request with JSON:API breaking the 1-to-1 relationship between a controller, a model and a policy).Edit: fix a typo
Beta Was this translation helpful? Give feedback.
All reactions