Menu

When Livewire Returns HTTP 403 but the Database Has Already Changed
📰

When Livewire Returns HTTP 403 but the Database Has Already Changed

DEV Community: laravel·djokage·2 days ago
#LpMattKi
#devtolaravel#devto#dev#livewire#json
Reading 0:00
15s threshold

I was investigating how Livewire handles authorization for #[Json] methods and found an interesting execution-order problem.

The issue appears when an application relies on a global ComponentHook::call() to authorize component actions.

In the tested Livewire 4.4.8 implementation, a method marked with #[Json] can execute before the global component authorization hook gets a chance to reject the call.

The important part is that the method can perform its database operation even though Livewire eventually returns HTTP 403.

The problem

Livewire uses separate listeners for JSON methods and global component hooks.

The relevant execution path is:

SupportJson receives the component call.

It identifies the method marked with #[Json] .

It checks the built-in method-level authorization attributes.

It executes the JSON method directly.

The global ComponentHookRegistry listener runs afterward.

The custom authorization hook rejects the request.

At that point, the method body has already executed.

Relevant…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.