/

CVE-2026-85604

Severity:

HIGH RISK

(8.8)

PHP Code Injection (CWE-94) in Grav Twig Sort Filter

CVE-2026-85604

Deferred

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

Impact:

Remote Code Execution

Severity:

HIGH RISK

(8.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

Grav contains a code injection vulnerability in the Twig sort filter that can allow an authenticated user with page-write permissions to execute arbitrary PHP code as the web server user. The issue becomes risky when attacker- controlled content is rendered through a sandboxed Twig environment whose function restrictions can be bypassed.

Affected context

The vulnerability affects Grav installations using the vulnerable Twig extension behavior in versions up to and including 2.0.17. It requires a rendering path, such as page content or plugin-generated output, where an authenticated user with page-write capabilities can influence Twig input and invoke the sort filter within the sandbox.

Exploit preconditions

  • Attack surface: Twig template rendering through Grav pages or integrated

plugins

  • Required access: An authenticated account with page-write permissions,

such as admin.pages or api.pages.write

  • Trigger point: Rendering attacker-controlled content that reaches the Twig

sort filter

  • Why exploitation is possible: The sort wrapper disables the sandbox

argument, and the remaining function restrictions do not adequately block

a PHP include-capable function, allowing attacker-controlled code execution

Why this happens

The underlying bug is an incomplete enforcement of Twig sandbox restrictions in GravExtension.php. Unlike related filters that preserve the sandbox state, the sort function wrapper hardcodes the isSandboxed argument to false and permits a plain function name to be resolved. Because the denylist does not comprehensively restrict include-capable PHP functionality, attacker- controlled template data can cross from a supposedly constrained expression into PHP execution. This behavior maps to CWE-94, Improper Control of Generation of Code.

Potential impact

  • An attacker may execute arbitrary PHP code as the web server user.
  • The attacker could read, modify, or delete application and site data.
  • The compromise could enable defacement, credential exposure, or persistence.
  • The attacker may use the web server account to access other reachable

services or resources.

General mitigation guidance

Mitigation generally focuses on preserving sandbox enforcement across every Twig filter and preventing template-controlled values from selecting callable PHP functions. Secure-by-default designs should use explicit, allowlisted operations rather than denylisted function names, keep user-authored content separate from executable templates, and validate content before rendering. Page-writing privileges should be limited to trusted users, while the web process should run with the minimum filesystem and service permissions required. Plugin integrations should also avoid rendering untrusted frontmatter as executable template input.

How teams detect issues like this

Detection can include static analysis for wrappers that override sandbox or authorization parameters, dynamic callable resolution based on template input, and denylist-only restrictions around PHP functions. Code review should examine every Twig extension and confirm that sandbox state is consistently propagated. Monitoring can flag unexpected page updates, suspicious template expressions, anomalous web-process child activity, and PHP file access originating from the application account. Automated security review tools may help identify unsafe callable resolution and incomplete allowlists.

Sources

SourceLink
github.comgithub.com/getgrav/grav/security/advisories/GHSA-p6qj-p5m7-f62h
vulncheck.comvulncheck.com/advisories/grav-before-2.0.19-remote-code-execution-via-sort-filter

Frequently asked

questions

Exploitation generally requires authentication with page-writing permissions,

including permissions represented by admin.pages or api.pages.write. An

unauthenticated attacker would typically need an additional path to obtain

or abuse those privileges.

It can be remotely triggered through Grav's authenticated page or API

interfaces when submitted content is later rendered by a vulnerable Twig

path. The attacker still needs the required authenticated write access.

Ensure every Twig extension preserves sandbox enforcement and uses explicit

allowlists for permitted operations. User-controlled content should never be

able to select arbitrary PHP callables or executable template behavior.

Apply least privilege to page authors and the web process, review custom Twig

extensions for sandbox-state handling, separate content from templates, and

enforce security testing and policy checks for dynamic callable resolution.

Find out what's already
exploitable in your codebase.