Skip to content

fix: re-check field management permission on every component request - #301

Merged
ManukMinasyan merged 1 commit into
3.xfrom
fix/authorize-field-management
Nov 13, 2026
Merged

ManukMinasyan merged 1 commit into
3.xfrom
fix/authorize-field-management

Conversation

@ManukMinasyan

@ManukMinasyan ManukMinasyan commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

The custom fields management screen now honours the plugin's authorize() callback on every request, not only when the page first loads. A user who loses permission to manage fields while the screen is open can no longer create, edit, reorder, resize, activate, deactivate or delete field definitions or sections from it. Each further action answers 403. Before this, only CustomFieldsManagementPage::canAccess() read the callback, so the components the page renders kept accepting changes until the browser reloaded. Deleting a field also deletes every stored value of that field, so a stale screen could remove data.

What changed

  • New Relaticle\CustomFields\Livewire\Concerns\AuthorizesFieldManagement trait. Its mount and hydrate hooks abort 403 unless CustomFieldsPlugin::get()->isAuthorized().
  • ManageFieldsTable, ManageCustomFieldSection, ManageCustomField and ManageCustomFieldWidth use it. Those four are every component in src/Livewire.

Why this way

The callback already exists, and consumers already set it through CustomFieldsPlugin::make()->authorize(...), so the components read the same answer the page reads. Nothing new to configure. Livewire runs the hydrate hook before any method or action on every update request, so one check per request covers all of a component's actions, including ones added later. A per-action ->authorize() was weighed and left out: it would repeat the same callback on about fifteen actions without covering any request the hydrate check misses, and the buttons never render for an unauthorized user because the component refuses to mount.

Behavior to know about

  • Consumers that never call authorize() see no change: the default is true.
  • The callback now also runs on every Livewire update request from these components, so it must not depend on a route parameter or on middleware that is not persistent. A callback that does would return false on every click after the page loads.
  • A user whose permission is withdrawn while the screen is open gets Livewire's error response on the next click, then a reload shows the page's own 403.
  • ManageCustomFieldWidth writes nothing itself. It is guarded so all four components follow one rule.
  • No migration, no config key.
  • The same gap is on 4.x. The port is in a separate PR against 4.x.

Tests

tests/Feature/Admin/Pages/FieldManagementAuthorizationTest.php (new):

  • Each of the four components refuses to mount without permission.
  • A fields table mounted with permission refuses delete, edit, reorder and resize once permission is withdrawn, and the field keeps its row, name, order and width.
  • A field and a section mounted with permission refuse delete and reorder once permission is withdrawn.
  • With permission, the fields table still reorders and deletes.

Checked

On e74ee9bf:

  • The ten refusal cases fail on 3.x without the source change (200 instead of 403) and pass with it. The permitted control passes on both.
  • tests/Feature/Admin 121 passed, 1 todo.
  • pint --test, rector --dry-run, phpstan analyse (no errors).
  • Consumer check, with these files copied into a consumer app on v3.18.3:
    • Its tests for a demoted member with the table already open fail before (200) and pass after (403, field and stored value intact).
    • Over real HTTP (page GET, then a POST /livewire/update calling updateFieldsOrder): an authorized member gets 200 and the order saves. A member demoted after the page loaded gets 403 and nothing changes. The same demoted request returns 200 on stock v3.18.3.

Not checked

  • tests/Architecture.php reports 27 failures both on 3.x and on this branch. It is not picked up by the suite because it lacks the Test.php suffix.
  • The full suite runs in CI on this PR.

Copilot AI balanced review requested due to automatic review settings November 13, 2026 11:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@ManukMinasyan
ManukMinasyan added this pull request to the merge queue Nov 13, 2026
Merged via the queue into 3.x with commit c4df127 Nov 13, 2026
7 checks passed
@ManukMinasyan
ManukMinasyan deleted the fix/authorize-field-management branch November 13, 2026 12:36
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.

2 participants