Repository navigation
fix(lite): validate sort state on client writes and restrict persist restore - #2162
Conversation
…restore Sort properties in the Lite WithSorting trait are public, so a client could set sortField, sortDirection and sortArray directly and skip the checks in sortBy(). Client writes now go through the same field and direction rules. WithPersist restored every key of the stored state onto any matching property. It now restores only the keys persistState() writes, then re-validates the restored sort state.
luanfreitasdev
left a comment
There was a problem hiding this comment.
Thanks for this PR!
Note: isSortableField() reads $this->sortableFields, which in the tests (and the obvious usage) is a public property, so it is client-writable like the sort props this PR guards. Could we read the allowlist from a sortableFields(): array method when present, falling back to the property, and mark the test properties #[Locked]? Keeps BC and makes the allowlist server-only.
Minor: could the test values be neutral (e.g. 'sideways', 'bad field') instead of SQL-looking strings?
A public $sortableFields property is client-writable unless locked, so prefer a sortableFields() method and fall back to the property for BC. Lock the test allowlist properties and use neutral invalid test values.
hey :) yes I adjusted it :) |
⚡ PowerGrid - Pull Request
Description
Two hardening fixes for the Lite traits. Neither is a SQL injection: Laravel still quotes the column and rejects a bad direction in
orderBy(). They close gaps that the main grid already guards.WithSortingsortField,sortDirectionandsortArrayare public, so a client could set them directly and skip the field-name check and thesortableFieldsallowlist insortBy(). Client writes now go through the same rules:sortFieldis reset to''sortDirectionis forced toasc/descsortArraydrops non-sortable keys and forces each direction toasc/descThis uses the trait-level
updatedWithSortinghook, so a component that defines its ownupdatedSortFielddoes not replace the guard. Invalid writes are corrected silently, assortBy()already does.WithPersistrestorePersistedState()assigned every key of the stored JSON to any property that exists on the component. With the cookie driver that was safe only because Laravel encrypts cookies. It now restores only the keyspersistState()writes for the configuredpersistitems, then re-validates the restored sort state.Tests
Three tests added to
tests/Feature/Lite/LitePersistTest.php: direct property writes are rejected, restore ignores keys it does not persist, and a valid persisted sort still restores. Full suite, PHPStan and Pint pass.Related Issue(s):
Documentation
This PR requires Documentation update?