Do a policy check at the resource level before any other callbacks - #986
Conversation
d3907ae to
bd53b8c
Compare
|
The coverage going down is because we don't check the |
There was a problem hiding this comment.
I'm not sure about this one, using check_resource_access feels a bit weird to me:
- I find it more natural if the public methods of policies correspond to the actions in the controller
- I think it solves the same problem as you do with
policy_scope: I don't see a lot of cases where the user would get passedpolicy_scope(and the policy that matches the action) but would currently get stopped bycheck_resource_access
Maybe we should split this problem in two:
- A user who is not logged in, should have no way to find out details about what's in the database
- A user who is logged in, should not know about the ids of objects it can't see.
For the first problem, I think we might be better of with an early return of unauthorized. Rather than having to check this in each policy, we know that signing in is the only action that doesn't require a user. I guess either by:
- Updating our
authenticate_userto require the user to be present or returning unauthorized (and then usingskip_before_actionfor the sign in action) - Adding something like
require_user!and adding this as a before action (either per controller, or withskip_before_action). - We could make our policies a closed system, and also make some exception for creating auth tokens
For the second problem (which I don't worry about as much, I'm not sure what I could do by knowing the id of a secret playlist someone else made 🤷 ), the policy_scope should be enough?
|
The problem with just using policy_scope is that the HTTP status unauthorized users get will still be a 404, which doesn't necessarily match the truth, since they might be able to view the resource if they were logged in. In my view, this is essentially an early unauthorized return. It's just set up a bit more flexibly, allowing to also use that early unauthorized return to also deny regular users any access to moderator-only routes (like locations and cover filenames). The closed system solution might also be good though (I think we can also make that work for cover filenames and locations by expanding that check a bit in a custom constructor in those policy classes.) WDYT? |
9ddea37 to
0ca9e46
Compare
|
Reworked it to be a closed system, where the |
robbevp
left a comment
There was a problem hiding this comment.
👍 Just noticed one method that should be removed
…source A similar issue existed for logged-in users for other user's secret records (auth tokens and playlists, in practice). By policy scoping the `find` calls, authorized users will always get a 404 for records they don't have access to, whether that record exists or not.
0ca9e46 to
ac16eef
Compare
Expect for the auth callback, of course. This fixes a leak in our policy/resource handling, where a user could know whether a record with a certain ID existed based on the HTTP response.
A similar issue existed for logged-in users for other user's secret records (auth tokens and playlists, in practice). By policy scoping the
findcalls, authorized users will always get a 404 for records they don't have access to, whether that record exists or not.