# CVE-2026-85604: Grav before 2.0.18 Remote Code Execution via sort filter

The Markdown version of <https://upatch.dev/cve/CVE-2026-85604>. Last updated 25 Nov 2026.

## At a glance

CVE-2026-85604 is rated High 8.7 (CVSS 4.0, CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X). It affects Grav (getgrav) and was published on 4 Sept 2026. It is not in CISA's Known Exploited Vulnerabilities catalog. Its EPSS score is 0.9%: the estimated chance it is exploited in the next 30 days, as of 24 Nov 2026. The upatch `cve-2026-85604-exec-block` mitigates it, and is vetted (merged into the registry).

A upatch is a signed BPF program that shirudo loads into a running Linux kernel to block the code path this CVE's exploit takes. It holds the line until the fix ships; it does not replace patching.

## The vulnerability

CVE-2026-85604 (GHSA-p6qj-p5m7-f62h), published on 4 September 2026, is a remote code execution vulnerability in Grav before 2.0.19 (affecting versions up to 2.0.17). In `system/src/Grav/Common/Twig/Extension/GravExtension.php`, the `sortFunc` wrapper calls `CoreExtension::sort($env, false, $array ?? [], $arrow)`, hardcoding Twig's `$isSandboxed` argument to `false`. Because that flag is what enforces Twig's rule that callables in sandbox mode must be `Closure` instances, the `|sort` filter accepts a plain string function name inside the sandbox where `|map`, `|filter` and `|reduce` refuse it. The remaining `Utils::isDangerousFunction()` denylist misses `spl_autoload`, which performs a PHP `include` of a lowercase path and extension, allowing an authenticated user with page-write rights (`admin.pages` or `api.pages.write`) to include their own `.md` page file and run arbitrary PHP code and OS commands as the web server user.

### Official description

Grav before 2.0.18 (affected versions <= 2.0.17) contains a remote code execution vulnerability in the Twig sort filter. The sortFunc wrapper in GravExtension.php hardcodes Twig's isSandboxed argument to false, so unlike |map/|filter/|reduce, |sort accepts a plain function name inside the sandbox; the remaining denylist misses spl_autoload, which performs a PHP include. An authenticated user with only page-write rights (admin.pages or api.pages.write) can supply a crafted payload (e.g., via form frontmatter rendered by the Email plugin) that invokes spl_autoload through the sort filter, resulting in arbitrary PHP execution as the web server user.

## What the upatch does

The program attaches to `lsm/bprm_check_security` and returns `-EPERM` when:

1. The current task or its parent task has a command name starting with `php` (such as `php` or `php-fpm`), and
2. The task's current working directory is named `grav` or `grav-admin`.

Refusals from earlier BPF LSM programs on the same hook are preserved. A per-CPU array map `refused` counts blocked executions.

The policy: [`cve-2026-85604-exec-block.bpf.c`](https://github.com/copper-helm/upatch-registry/tree/main/upatches/cve-2026-85604), 76 lines of BPF C attached at `lsm/bprm_check_security`, licensed GPL-2.0 OR BSD-2-Clause.

## Side effects

- PHP processes whose working directory is `grav` or `grav-admin` cannot `execve` external binaries (such as `/bin/sh`, `sendmail` or `git`).
- Normal Grav page rendering, Twig template evaluation, file caching and PHP-internal operations do not spawn external binaries and continue working.
- Other processes on the machine, including root shells, `sshd` and package managers, are unaffected.

## Preemption model and cost

The program holds no locks and shares only a per-CPU counter updated with `__sync_fetch_and_add`, making it safe under all kernel preemption models including `PREEMPT_LAZY`, `PREEMPT_DYNAMIC` and `PREEMPT_RT`. It runs only on `execve` (`bprm_check_security`), checks the 3-byte `php` prefix of `comm` first, and returns immediately for all non-PHP processes.

## Affected versions

| Software | Affected  | Fixed in |
| -------- | --------- | -------- |
| Grav     | <= 2.0.17 | 2.0.19   |

## How it was tested

On Grav 2.0.17, the loaded upatch blocked subprocess execution triggered after reaching the Twig sort filter sandbox bypass with spl_autoload.

- **Tested:** 25 Nov 2026
- **Target:** Grav 2.0.17 (grav-admin-v2.0.17.zip) on PHP 8, loopback only
- **Kernel:** 7.4-shirudo-ci-20261123
- **Architecture:** x86_64
- **Distribution:** Ubuntu 26.04

### Results

| State           | Twig \|sort('spl_autoload') includes probe and spawns /bin/true |
| --------------- | --------------------------------------------------------------- |
| Before loading  | reached                                                         |
| Upatch loaded   | blocked                                                         |
| After unloading | reached                                                         |

## How to apply

Build the upatch from source, sign it with your own shirudo key, and publish it to your own OCI registry. Machines that follow your upatch tree load it within about a minute.

Build and sign:

```sh
git clone https://github.com/copper-helm/upatch-registry
cd upatch-registry
tools/build <shirudo-checkout> <keys-dir> 1.0.0 upatches/cve-2026-85604
```

Publish and roll out:

```sh
shirudo bpm push build/packages/cve-2026-85604-1.0.0.bee oci://<registry>/<namespace>/cve-2026-85604 --keys-dir <keys-dir>
shirudo bpm tree append build/packages/cve-2026-85604-1.0.0.bee oci://<registry>/<namespace>/<tree> --tree-id <tree-id> --keys-dir <keys-dir>
```

## Review

- Contributors: romanlab.
- Reviewers: none recorded yet.

## Sources and links

- [GitHub Security Advisory GHSA-p6qj-p5m7-f62h](https://github.com/getgrav/grav/security/advisories/GHSA-p6qj-p5m7-f62h)
- [VulnCheck Advisory for CVE-2026-85604](https://www.vulncheck.com/advisories/grav-before-2.0.19-remote-code-execution-via-sort-filter)
- [Fix commit 893d3706b514](https://github.com/getgrav/grav/commit/893d3706b514cafaddc5a5731b2c770214ead36b)
- [Grav 2.0.17 release](https://github.com/getgrav/grav/releases/tag/2.0.17)

### Links

- [CVE-2026-85604 on upatch.dev](https://upatch.dev/cve/CVE-2026-85604) (this page, as HTML)
- [NVD](https://nvd.nist.gov/vuln/detail/CVE-2026-85604)
- [CVE.org](https://www.cve.org/CVERecord?id=CVE-2026-85604)
- [CWE-94](https://cwe.mitre.org/data/definitions/94.html)
- Upatch source: [upatches/cve-2026-85604](https://github.com/copper-helm/upatch-registry/tree/main/upatches/cve-2026-85604)

### More references from NVD (2)

- [github.com](https://github.com/getgrav/grav/security/advisories/GHSA-p6qj-p5m7-f62h)
- [vulncheck.com](https://www.vulncheck.com/advisories/grav-before-2.0.19-remote-code-execution-via-sort-filter)
