# livewire-powergrid: SQL injection via sortDirection in naturalSort queries

Livewire-bound sortDirection property flows unvalidated into a raw ORDER BY in naturalSort queries, enabling blind SQL injection via POST /livewire/update.

- Payout: Research
- Severity: high
- Program: livewire-powergrid
- Found by: BiiTts
- Disclosed: 2026-11-25
- CVE: CVE-2026-65971
- Write-up quality: 7/10
- Original: https://github.com/advisories/GHSA-7fgc-3h6c-698r
- Library page: https://bugbountylibrary.com/r/ghsa%3AGHSA-7fgc-3h6c-698r
- Tags: area:web domain:web impact:data-leak impact:pii-leak kind:research platform:ghsa sev:high tech:php technique:blind technique:source-review vuln:sqli

**Target:** Livewire component update endpoint (POST /livewire/update) in Laravel app
**Root cause:** The public Livewire property sortDirection is substituted verbatim into a raw ORDER BY via resolvePlaceholders and orderByRaw, with no asc/desc whitelist. Setting sortField="" skips the Sorting pipeline's validating orderBy while ColumnRawQueries still applies the tainted naturalSort expression.
**Steps:**
1. Identify a PowerGrid table whose column uses `->naturalSort(true)`.
2. Capture the PowerGrid component snapshot from the page and a valid CSRF token.
3. Send `POST /livewire/update` with `components[0].updates = {"sortField": "", "sortDirection": "asc, (SELECT SLEEP(3))"}`.
4. Observe delayed response confirming injection; swap in boolean/time-based subqueries to extract data.
**How found:** Code review of the data flow: noticed sortDirection is a public Livewire property with no whitelist, traced it through resolvePlaceholders into getSortSqlByDriver's orderByRaw, and realized setting sortField="" skips the Sorting pipeline's validating orderBy while the raw pipeline still runs.
**Exploitation:** Attacker with access to the Livewire update endpoint sets sortField empty to bypass Laravel's direction validation and injects SQL into sortDirection. Blind boolean/time-based oracles (SLEEP, extractvalue error-based) leak arbitrary readable data such as secrets and password hashes; stacked queries blocked by default PDO MySQL driver.
**Escalation:** Cross-tenant data exfiltration in multi-tenant/admin apps; read-oriented confidentiality impact only.
**Insight:** When a framework validates a value in one code path, look for sibling pipelines that consume the same property without validation; an empty/absent sibling field can disable the guarded path while the unguarded raw path still executes.

## Proof of concept (copied exactly from the original report)

**Livewire update request injecting sortDirection**

```
POST /livewire/update
components[0].snapshot = <the PowerGrid component snapshot from the page>
components[0].updates  = {"sortField": "", "sortDirection": "asc, (SELECT SLEEP(3))"}
```

**Time-based blind SQLi payloads**

```
asc                                 -> 0.02s   (baseline)
  asc, (SELECT SLEEP(3))              -> 9.04s   (injection executes)
  asc, (SELECT SLEEP(3) WHERE (SELECT secret FROM rooms LIMIT 1) LIKE 'TOPSECRET%')  -> 9.03s  (TRUE — value leaks)
  ... LIKE 'ZZZ%'                     -> 0.02s   (FALSE — boolean oracle)
```

