In this episode, we notice a missing authorization check on our endpoint's index (or "show") action. This is a pretty important security detail—without it, anyone could access the details of any endpoint just by guessing or supplying an ID!
So, we quickly remedy this by adding a new method to our Endpoint Policy, specifically for checking if a user can 'show' or view an endpoint. The logic stays similar to our other policy methods: making sure the current user owns the resource they're trying to access.
To keep our codebase consistent, we wrap this check in a form request, even though this is a GET operation. We create a new EndpointShowRequest
for authorization, swap it into the controller, and keep everything nice and tidy. As a result, our controller stays clean, all our authorization logic is centralized, and we remain consistent with our previous approach for other actions like update and destroy.
At the end, we test things out and confirm it's all working correctly! With this fix in place, our app's endpoint details are locked down and only visible to the right users.