Livewire: Authorization bypass in #[Authorize] via reordered parameter keys and #[Json] execution order
As published by the sources
Affected packages
- Affected
>=4.3.0,<4.4.8Fixed in4.4.8
Derived from the fixed versions above
What to do
Upgrade livewire/livewire to 4.4.8 or later.
composer update livewire/livewire --with-dependencies
To see which version you have installed, run composer show vendor/package. Running composer audit lists the known advisories that match your installed versions.
Quoted from the original advisory
Details
Impact
Three issues allowed actions protected by the #[Authorize] attribute to run against records the current user is not authorized for:
- Out-of-order parameter keys on actions.
#[Authorize]resolved a model parameter by its array key, while the action itself received parameters positionally. A request sending params as an object with reordered integer keys (e.g.{"1": 2, "0": 1}) could pass authorization with a record the user owns while the action received a different record. With#[Authorize('delete', 'comment')]ondeleteComment(Comment $comment), a user could delete another user's comment. - The same issue on event listeners. Methods using both
#[On]and#[Authorize]with a model parameter were affected in the same way through the__dispatchcall. #[Json]methods ran before authorization. When a method had both#[Json]and#[Authorize], the method body executed before the authorization check. The response was still a 403, but any side effects (such as database writes) had already happened.
Only applications using the #[Authorize] attribute are affected: on methods that take model parameters (issues 1 and 2), or on #[Json] methods (issue 3). Authorization performed inside the method (e.g. $this->authorize(...)) is not affected. Livewire 3.x is not affected.
Patches
Fixed in v4.4.8. Call and event parameters must now be a list or use named (string) keys, otherwise the request is rejected, and #[Json] methods are authorized before they run.
Workarounds
Upgrade to v4.4.8. If you can't upgrade right away, call $this->authorize(...) inside affected methods instead of relying on the #[Authorize] attribute.
Credits
Reported by Yousef Aman (@yousef-aman).
References
- Advisoryhttps://github.com/advisories/GHSA-mhf7-xp6r-6qrc
- Webhttps://github.com/livewire/livewire/security/advisories/GHSA-mhf7-xp6r-6qrc
- Webhttps://github.com/livewire/livewire/commit/822a4fa9b1e1123691133a2e2eb379a3dab11191
- Packagehttps://github.com/livewire/livewire
- Webhttps://github.com/livewire/livewire/releases/tag/v4.4.8