Repository navigation
fix: only let the actor plug grant actor and authorization controls - #450
Merged
Merged
Conversation
The toggle_authorizing, toggle_actor_paused, clear_actor and set_actor events were handled for every client, even when the sidebar hid their controls. With a custom actor plug, any dashboard user could send toggle_authorizing or clear_actor from the browser console and run every read and action with authorization off. Actor plugs now return actor_controls?, which defaults to false. The default plug sets it, since its settings come from the browser anyway. When it is off, the dashboard ignores those events and hides the sidebar controls and the "Set as actor" buttons. A custom plug can set it for users who should have those controls. Fixes #449
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #449
With a custom actor plug, any dashboard user can turn off authorization from the browser console.
AshAdmin.PageLivehandlestoggle_authorizing,toggle_actor_paused,clear_actorandset_actorfor every client. The sidebar hides those controls when no actor resources are listed, but that only hides the buttons.The getting started guide's custom plug returns only
[actor: current_user], so the page starts withauthorizing: trueand no actor resources. If a user sends atoggle_authorizingevent over the LiveView socket anyway,authorizingflips tofalse, and every read, create, update, destroy and generic action runs withauthorize?: falseuntil the page is reloaded.clear_actordoes the same in one step.set_actordoesn't need the console: the "Set as actor" buttons render for anyactor? trueresource, whichever plug is used, so a user can make another user the actor.With the default plug this changes nothing. Its actor and authorization settings come from cookies the browser controls, by design. In the issue's repro (default plug, no actor resources),
authorizingalready defaults tofalse, so the toggle can only turn authorization on.Changes
actor_controls?. It decides whether the dashboard user may change the actor or turn off authorization.PageLivedefaults it tofalse, andAshAdmin.ActorPlug.Plugreturnstrue. Custom plugs that don't set it now always enforce authorization.PageLiveignorestoggle_authorizing,toggle_actor_paused,clear_actorandset_actorwhenactor_controls?is off, in a singlehandle_event/3clause.Table,DataTableandShow, so the UI and the handlers agree.Show.render_show/5is also reached fromGenericAction, which passes noactor_controls, so it treats a missing one asfalse.actor_controls?: truefor some users, for example super admins.PageLivethen lists the actor resources itself if the plug doesn't, so the sidebar controls appear. That list moved fromAshAdmin.ActorPlug.PlugtoAshAdmin.Helpers.actor_resources/1so both can use it.Upgrading
This changes behavior only for apps with a custom actor plug whose users used the actor or authorization controls. Those controls only showed if the plug returned
actor_resources. Such a plug needs to returnactor_controls?: trueto keep them. Changes made with the controls still last only until reload, since the plug sets the actor again on mount.Tests
The actor plug is read with
Application.compile_env/3, so the test config now selectsAshAdmin.Test.ActorPlug. It delegates to the default plug except on two new test routes, whosesessionMFA marks them:/api/custom-actor/adminacts like the guide's custom plug:[actor: nil]./api/custom-actor-controls/adminaddsactor_controls?: true.The tests use
AshAdmin.Test.ProfileLanguage, whose read policy requires an actor:toggle_authorizingorclear_actorevents. Before this change, both events made the record visible.toggle_actor_pausedandset_actorevents push nothing.set_actortests.NOTE: I did not test this in a host app; the tests above drive
PageLivethroughPhoenix.LiveViewTest.Contributor checklist
Leave anything that you believe does not apply unchecked.