<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: djokage</title>
    <description>The latest articles on DEV Community by djokage (@djokage).</description>
    <link>https://dev.to/djokage</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F622652%2F24b75b99-808a-4cf7-ac0f-575702f341b4.png</url>
      <title>DEV Community: djokage</title>
      <link>https://dev.to/djokage</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/djokage"/>
    <language>en</language>
    <item>
      <title>When Livewire Returns HTTP 403 but the Database Has Already Changed</title>
      <dc:creator>djokage</dc:creator>
      <pubDate>Sun, 15 Nov 2026 01:39:55 +0000</pubDate>
      <link>https://dev.to/djokage/when-livewire-returns-http-403-but-the-database-has-already-changed-m03</link>
      <guid>https://dev.to/djokage/when-livewire-returns-http-403-but-the-database-has-already-changed-m03</guid>
      <description>&lt;p&gt;I was investigating how Livewire handles authorization for &lt;code&gt;#[Json]&lt;/code&gt; methods and found an interesting execution-order problem.&lt;/p&gt;

&lt;p&gt;The issue appears when an application relies on a global &lt;code&gt;ComponentHook::call()&lt;/code&gt; to authorize component actions.&lt;/p&gt;

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

&lt;p&gt;The important part is that the method can perform its database operation even though Livewire eventually returns HTTP 403.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem
&lt;/h2&gt;

&lt;p&gt;Livewire uses separate listeners for JSON methods and global component hooks.&lt;/p&gt;

&lt;p&gt;The relevant execution path is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;SupportJson&lt;/code&gt; receives the component call.&lt;/li&gt;
&lt;li&gt;It identifies the method marked with &lt;code&gt;#[Json]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;It checks the built-in method-level authorization attributes.&lt;/li&gt;
&lt;li&gt;It executes the JSON method directly.&lt;/li&gt;
&lt;li&gt;The global &lt;code&gt;ComponentHookRegistry&lt;/code&gt; listener runs afterward.&lt;/li&gt;
&lt;li&gt;The custom authorization hook rejects the request.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;At that point, the method body has already executed.&lt;/p&gt;

&lt;p&gt;Relevant source:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/livewire/livewire/blob/v4.4.8/src/Features/SupportJson/SupportJson.php" rel="noopener noreferrer"&gt;https://github.com/livewire/livewire/blob/v4.4.8/src/Features/SupportJson/SupportJson.php&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/livewire/livewire/blob/v4.4.8/src/ComponentHookRegistry.php" rel="noopener noreferrer"&gt;https://github.com/livewire/livewire/blob/v4.4.8/src/ComponentHookRegistry.php&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/livewire/livewire/blob/v4.4.8/src/EventBus.php" rel="noopener noreferrer"&gt;https://github.com/livewire/livewire/blob/v4.4.8/src/EventBus.php&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/livewire/livewire/blob/v4.4.8/src/Mechanisms/HandleComponents/HandleComponents.php" rel="noopener noreferrer"&gt;https://github.com/livewire/livewire/blob/v4.4.8/src/Mechanisms/HandleComponents/HandleComponents.php&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Database reproduction
&lt;/h2&gt;

&lt;p&gt;I tested this using a Laravel application with two authenticated users and a separate SQLite database.&lt;/p&gt;

&lt;p&gt;User 1 was a normal member.&lt;/p&gt;

&lt;p&gt;User 2 was an administrator and owner of the target database record.&lt;/p&gt;

&lt;p&gt;The member attempted to modify the administrator-owned record through a &lt;code&gt;#[Json]&lt;/code&gt; method. The application relied on the global component hook to reject unauthorized actions.&lt;/p&gt;

&lt;p&gt;The result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;authenticated_session_user_id=1
target_record_owner_user_id=2
http_response_status=403
database_value=modified-by-member
database_changed_by_user_id=1

CROSS-USER DATABASE PROOF PASSED
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The database was actually modified by user 1.&lt;/p&gt;

&lt;h2&gt;
  
  
  Control tests
&lt;/h2&gt;

&lt;p&gt;I tested other execution paths to compare the behavior.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Test&lt;/th&gt;
&lt;th&gt;HTTP&lt;/th&gt;
&lt;th&gt;Database&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Non-admin JSON action&lt;/td&gt;
&lt;td&gt;403&lt;/td&gt;
&lt;td&gt;Modified&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Non-admin ordinary action&lt;/td&gt;
&lt;td&gt;403&lt;/td&gt;
&lt;td&gt;Unchanged&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JSON with inline Gate authorization&lt;/td&gt;
&lt;td&gt;403&lt;/td&gt;
&lt;td&gt;Unchanged&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JSON with built-in &lt;code&gt;#[Authorize]&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;403&lt;/td&gt;
&lt;td&gt;Unchanged&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Administrator JSON action&lt;/td&gt;
&lt;td&gt;200&lt;/td&gt;
&lt;td&gt;Modified&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JSON request without CSRF token&lt;/td&gt;
&lt;td&gt;419&lt;/td&gt;
&lt;td&gt;Unchanged&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The inline &lt;code&gt;Gate::authorize()&lt;/code&gt; check and built-in &lt;code&gt;#[Authorize]&lt;/code&gt; attribute prevented the unauthorized database modification.&lt;/p&gt;

&lt;p&gt;This makes the execution-order difference particularly interesting.&lt;/p&gt;

&lt;h2&gt;
  
  
  Environment
&lt;/h2&gt;

&lt;p&gt;The original reproduction was performed with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PHP 8.4.24&lt;/li&gt;
&lt;li&gt;Laravel Framework 13.42.0&lt;/li&gt;
&lt;li&gt;Livewire 4.4.8&lt;/li&gt;
&lt;li&gt;SQLite&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The test used authenticated sessions and Laravel's HTTP request handling.&lt;/p&gt;

&lt;h2&gt;
  
  
  Impact
&lt;/h2&gt;

&lt;p&gt;Applications that rely exclusively on global &lt;code&gt;ComponentHook::call()&lt;/code&gt; authorization for &lt;code&gt;#[Json]&lt;/code&gt; methods can allow unauthorized application-side operations.&lt;/p&gt;

&lt;p&gt;The database test demonstrates cross-user record modification.&lt;/p&gt;

&lt;p&gt;This is an authorization problem, not a general bypass of Laravel's authorization system. Authorization performed inside the JSON method before the sensitive operation prevented the database write in my tests.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reproduction and evidence
&lt;/h2&gt;

&lt;p&gt;I published the research report and test material on GitHub.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Technical report:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/djokage/security-research/blob/main/reports/livewire-global-hook-authorization-order.md" rel="noopener noreferrer"&gt;https://github.com/djokage/security-research/blob/main/reports/livewire-global-hook-authorization-order.md&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Standalone reproduction:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/djokage/security-research/tree/main/reproducers/livewire-global-hook-json-order" rel="noopener noreferrer"&gt;https://github.com/djokage/security-research/tree/main/reproducers/livewire-global-hook-json-order&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Recorded database evidence:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/djokage/security-research/blob/main/reports/evidence/livewire-cross-user-db-proof.txt" rel="noopener noreferrer"&gt;https://github.com/djokage/security-research/blob/main/reports/evidence/livewire-cross-user-db-proof.txt&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Final note
&lt;/h2&gt;

&lt;p&gt;I am interested in independent reproduction and technical discussion.&lt;/p&gt;

&lt;p&gt;I would particularly like to hear from developers who use global Livewire component hooks for application-wide authorization.&lt;/p&gt;

&lt;p&gt;The important question is whether the global authorization hook should be able to reject a JSON action before the method body is executed.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>security</category>
      <category>livewire</category>
    </item>
  </channel>
</rss>
