CVE-2024-28119
JSON

8.8high

Grav vulnerable to Server Side Template Injection (SSTI) via Twig escape handler

Severity
8.8high CVSS:3.1 by GitHub_M
Exploit likelihood
1.58% (higher than 76% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
GitHub_M
Also known as
GHSA-2m7x-c7px-hp58

Description

Grav is an open-source, flat-file content management system. Prior to version 1.7.45, due to the unrestricted access to twig extension class from grav context, an attacker can redefine the escape function and execute arbitrary commands. Twig processing of static pages can be enabled in the front matter by any administrative user allowed to create or edit pages. As the Twig processor runs unsandboxed, this behavior can be used to gain arbitrary code execution and elevate privileges on the instance. Version 1.7.45 contains a patch for this issue.

Affected

Product or packageVersionsReported by
getgrav grav< 1.7.45, before 1.7.45CVE List, NVD
getgrav/grav (Packagist)before 1.7.45GitHub Advisory Database

All scores

GitHub_M8.8high CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
GitHub8.8high CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
NVD8.8high CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H

Classification

CWE-94

SSVC (CISA-ADP): exploitation poc, automatable no, technical impact total.

What each source says

CVE List

Grav is an open-source, flat-file content management system. Prior to version 1.7.45, due to the unrestricted access to twig extension class from grav context, an attacker can redefine the escape function and execute arbitrary commands. Twig processing of static pages can be enabled in the front matter by any administrative user allowed to create or edit pages. As the Twig processor runs unsandboxed, this behavior can be used to gain arbitrary code execution and elevate privileges on the instance. Version 1.7.45 contains a patch for this issue.

GitHub Advisory Database
Summary

Due to the unrestricted access to twig extension class from grav context, an attacker can redefine the escape function and execute arbitrary commands.

Details

https://github.com/twigphp/Twig/blob/3.x/src/Extension/EscaperExtension.php#L99

/**
     * Defines a new escaper to be used via the escape filter.
     *
     * @param string   $strategy The strategy name that should be used as a strategy in the escape call
     * @param callable $callable A valid PHP callable
     */
    public function setEscaper($strategy, callable $callable)
    {
        $this->escapers[$strategy] = $callable;
    }

Twig supports the functionality to redefine the escape function through the setEscaper method. However, that method is not originally exposed to the twig environment, but it is accessible through the payload below.

{{ grav.twig.twig.extensions.core.setEscaper('a','a') }}

At this point, it accepts callable type as an argument, but as there is no validation for the $callable variable, attackers can set dangerous functions like system as the escaper function.

PoC
{{ var_dump(grav.twig.twig.extensions.core.setEscaper('system','twig_array_filter')) }}
{{ var_dump(['id'] | escape('system', 'system')) }}
Impact

Twig processing of static pages can be enabled in the front matter by any administrative user allowed to create or edit pages. As the Twig processor runs unsandboxed, this behavior can be used to gain arbitrary code execution and elevate privileges on the instance.

NVD (es)

Grav es un sistema de gestión de contenidos de archivos planos de código abierto. Antes de la versión 1.7.45, debido al acceso sin restricciones a la clase de extensión twig desde el contexto grav, un atacante podía redefinir la función de escape y ejecutar comandos arbitrarios. El procesamiento Twig de páginas estáticas puede ser habilitado en la portada por cualquier usuario administrativo autorizado a crear o editar páginas. Como el procesador Twig se ejecuta sin entorno de pruebas, este comportamiento se puede utilizar para obtener la ejecución de código arbitrario y elevar los privilegios en la instancia. La versión 1.7.45 contiene un parche para este problema.

References

Sources

SourceRecordLicence
CVE ListCVE-2024-28119 changed 2024-08-21CVE Terms of Use
GitHub Advisory DatabaseGHSA-2m7x-c7px-hp58 changed 2026-09-10CC-BY-4.0
NVDCVE-2024-28119 changed 2026-06-17Public domain