Skip to content
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

[Issue-24] - Add a handler for resources not found #29

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

pedromlcosta
Copy link

** What's new **

Issue-24 - Implemented a "not found" handler, with the possibility of the user configuring a custom not found handler. Closes #24 .

Previously, a policy only allowed a boolean response. The not found handler adds the possibility of returning nil within the can? function of a policy, and the dep will then call the not found handler instead of the unauthorized handler.
Does not contain breaking changes.

@pedromlcosta pedromlcosta changed the title [Issue-24] - Fix: Wrong key for Ecto.Repo in the config files (:ecto instead of :ecto_repo) [Issue-24] - Add a handler for resources not found Nov 20, 2020
README.md Outdated Show resolved Hide resolved
lib/dictator.ex Outdated Show resolved Hide resolved
opts = unauthorized_handler.init(opts)
unauthorized_handler.call(conn, opts)

nil ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you feel about explicitly returning {:error, :not_found} instead of nil? Feels more explicit to me. cc @naps62 - any particular thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the return value of :can?/3. That function has a boolean response (enforced by the question mark, expanding that API would break the semantics)

I didn't notice at first that this is what the PR was doing: allowing :can?/3 to return nil. But that seems like a no-go to me

It also makes me wonder that this might be outside of the scope of dictator?
we could maybe allow an optional exists? callback to the policy, to be called before can?. But it would have to be opt-in, and I'm not sure how to handle that correctly

Copy link
Author

@pedromlcosta pedromlcosta Jul 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My original issue with verifying this outside Dictator and before the Dictator plug was called, was information could be leaked about whether or not an object exists to someone who we didn't check yet if they have the authorization to access that information.

But thinking a bit about what you're saying, maybe the approach was not the most correct one, since indeed it seems to fall out of the current responsibilities of the can? function. As for the scope of dictator, an optional exists? to me would look ok, just because of the reason above about leaking information when verifying authorizations, however, depending on the implementation we could incur on the same problem...

conn
|> send_resp(:not_found, "Object not found")
|> halt()
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expanding on my comment above, I'm not comfortable with the default response of an authorization library being a 404.

At most, this should be opt-in. Default behaviour should be the standard Unauthorized. Otherwise you risk leaking information to unauthorized users (i.e.: allowing the user to see that a certain object does not exist, even though he wouldn't have access to it in the first place)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a handler for resources not found
3 participants