Repository navigation
fix: re-check field management permission on every component request - #301
Merged
Merged
Conversation
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.
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, onlyCustomFieldsManagementPage::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
Relaticle\CustomFields\Livewire\Concerns\AuthorizesFieldManagementtrait. Itsmountandhydratehooks abort 403 unlessCustomFieldsPlugin::get()->isAuthorized().ManageFieldsTable,ManageCustomFieldSection,ManageCustomFieldandManageCustomFieldWidthuse it. Those four are every component insrc/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 thehydratehook 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
authorize()see no change: the default istrue.ManageCustomFieldWidthwrites nothing itself. It is guarded so all four components follow one rule.4.x. The port is in a separate PR against4.x.Tests
tests/Feature/Admin/Pages/FieldManagementAuthorizationTest.php(new):Checked
On
e74ee9bf:3.xwithout the source change (200 instead of 403) and pass with it. The permitted control passes on both.tests/Feature/Admin121 passed, 1 todo.pint --test,rector --dry-run,phpstan analyse(no errors).POST /livewire/updatecallingupdateFieldsOrder): 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.phpreports 27 failures both on3.xand on this branch. It is not picked up by the suite because it lacks theTest.phpsuffix.