Skip to content

fix: only let the actor plug grant actor and authorization controls - #450

Merged
zachdaniel merged 1 commit into
mainfrom
fix/guard-actor-events
Nov 20, 2026
Merged

zachdaniel merged 1 commit into
mainfrom
fix/guard-actor-events

Conversation

@bitwalker

Copy link
Copy Markdown
Contributor

Fixes #449

With a custom actor plug, any dashboard user can turn off authorization from the browser console. AshAdmin.PageLive handles toggle_authorizing, toggle_actor_paused, clear_actor and set_actor for 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 with authorizing: true and no actor resources. If a user sends a toggle_authorizing event over the LiveView socket anyway, authorizing flips to false, and every read, create, update, destroy and generic action runs with authorize?: false until the page is reloaded. clear_actor does the same in one step. set_actor doesn't need the console: the "Set as actor" buttons render for any actor? true resource, 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), authorizing already defaults to false, so the toggle can only turn authorization on.

Changes

  • Actor plugs now return actor_controls?. It decides whether the dashboard user may change the actor or turn off authorization. PageLive defaults it to false, and AshAdmin.ActorPlug.Plug returns true. Custom plugs that don't set it now always enforce authorization.
  • PageLive ignores toggle_authorizing, toggle_actor_paused, clear_actor and set_actor when actor_controls? is off, in a single handle_event/3 clause.
  • The same setting gates the sidebar's actor and authorization controls and the "Set as actor" buttons in Table, DataTable and Show, so the UI and the handlers agree. Show.render_show/5 is also reached from GenericAction, which passes no actor_controls, so it treats a missing one as false.
  • A custom plug can return actor_controls?: true for some users, for example super admins. PageLive then lists the actor resources itself if the plug doesn't, so the sidebar controls appear. That list moved from AshAdmin.ActorPlug.Plug to AshAdmin.Helpers.actor_resources/1 so both can use it.
  • The getting started guide's actor plug section now describes the default and the opt-in.

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 return actor_controls?: true to 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 selects AshAdmin.Test.ActorPlug. It delegates to the default plug except on two new test routes, whose session MFA marks them:

  • /api/custom-actor/admin acts like the guide's custom plug: [actor: nil].
  • /api/custom-actor-controls/admin adds actor_controls?: true.

The tests use AshAdmin.Test.ProfileLanguage, whose read policy requires an actor:

  • On the custom plug route, the controls and "Set as actor" buttons don't render, and the record stays hidden after toggle_authorizing or clear_actor events. Before this change, both events made the record visible. toggle_actor_paused and set_actor events push nothing.
  • On the opt-in route, the controls render, and clicking the authorization toggle shows the record.
  • With the default plug, the three toggles still work, as do the existing set_actor tests.

NOTE: I did not test this in a host app; the tests above drive PageLive through Phoenix.LiveViewTest.

Contributor checklist

Leave anything that you believe does not apply unchecked.

  • I accept the AI Policy, or AI was not used in the creation of this PR.
  • Bug fixes include regression tests
  • Chores
  • Documentation changes
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

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
@bitwalker bitwalker added the bug Something isn't working label Nov 19, 2026
@bitwalker
bitwalker requested a review from zachdaniel November 19, 2026 20:10
@bitwalker
bitwalker added this pull request to stack #452 November 19, 2026 20:23
@zachdaniel
zachdaniel merged commit 4f84654 into main Nov 20, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

toggle_authorizing, toggle_actor_paused and clear_actor event are all accessible from the console when they're not rendered in ui

2 participants