Angus proposes adding a new server-side plugin API to allow modifying the outcome of Guardiancan_* checks via before and after hooks angus. The goal is to enable plugins to alter check results, such as preventing edits on remote posts. pmusaraj raises concerns about security and potential conflicts with multiple plugins using after hooks. Angus acknowledges the risks and suggests limiting the PR to before checks only, which would address immediate needs while reducing complexity angus. pmusaraj agrees to proceed with just the before checks.
Something I’ve come across a few times when building plugins is the need to modify the outcome of Guardiancan_* checks. I’ve come across it again in the ActivityPub Plugin:
I’ve just raised a draft PR that adds a new server-side plugin api method that allows you to register before and after checks to guardian can_* methods, affording the ability to change the outcome of the method. For example
add_guardian_check(:before, :edit_post) do |guardian, result, post|
!post.activity_pub_remote?
end
I don’t see any issues with the before_* register. The after_* register is a little trickier. Security-wise, the after_* register means plugins can override core in ways that may be unsafe. Obviously plugins can do this in all sorts of ways, but the plugin API shouldn’t facilitate it even further.
Also, what happens if multiple plugins consume the after_* hook? Which one wins?