CVE-2025-66299: Security Sandbox Bypass with SSTI (Server Side Template Injection) in the Grav CMS

Published Dec 1, 2025
·
Updated

Summary

Grav CMS is vulnerable to a Server-Side Template Injection (SSTI) that allows any authenticated user with editor permissions to execute arbitrary code on the remote server, bypassing the existing security sandbox.

Details

Grav CMS uses a custom sandbox to protect the powerful Twig methods such as registerUndefinedFilterCallback(). These methods are designed to prevent SSTI attacks by denying the execution of dangerous PHP functions (e.g., exec(), passthru(), system(), etc.) within Twig template directives.

The current defense mechanism relies on a blacklist of prohibited functions (PHP, Twig), checked through the isDangerousFunction() method in the file system/src/Grav/Common/Twig.php:

php $this->twig->registerUndefinedFilterCallback(function (string $name) use ($config) { $allowed = $config->get('system.twig.safefilters'); if (isarray($allowed) && inarray($name, $allowed, true) && functionexists($name)) { return new TwigFilter($name, $name); } if ($config->get('system.twig.undefinedfilters')) { if (functionexists($name)) { if (!Utils::isDangerousFunction($name)) { usererror("PHP function {$name}() used as Twig filter. This is deprecated in Grav 1.7. Please add it to system configuration: system.twig.safefilters", EUSERDEPRECATED);

return new TwigFilter($name, $name); }

/ @var Debugger $debugger / $debugger = $this->grav['debugger']; $debugger->addException(new RuntimeException("Blocked potentially dangerous PHP function {$name}() being used as Twig filter. If you really want to use it, please add it to system configuration: system.twig.safefilters")); }

return new TwigFilter($name, static function () {}); }

return false; });

In this code, the isDangerousFunction() check is bypassed if the filter defined in the $name variable is considered safe. Only an administrator can mark a function as safe by adding it to the system.twig.safefilters configuration properties (whitelists that are empty by default) in the system/config/system.yaml file.

Notably, the Twig class is defined within the system/src/Grav/Common/Twig.php file, and the Twig object (and environment) is instantiated there:

php / Class Twig @package Grav\Common\Twig / class Twig { / @var Environment / public $twig; / @var array / public $twigvars = []; / @var array / public $twigpaths; / @var string / public $template;

// Constructor public function construct(Grav $grav) { $this->grav = $grav; $this->twigpaths = []; }

// Twig initialization method public function init() { if (null === $this->twig) { / @var Config $config / $config = $this->grav['config']; / @var UniformResourceLocator $locator / $locator = $this->grav['locator']; / @var Language $language / $language = $this->grav['language'];

$activelanguage = $language->getActive(); ... } } }

Since the security sandbox does not fully protect the Twig object, it is possible to interact with it (e.g., call methods, read/write attributes) through maliciously crafted Twig template directives injected into a web page. This allows an authenticated editor to add arbitrary functions to the Twig attribute system.twig.safefilters, effectively bypassing the Grav CMS sandbox.

Proof of Concept (PoC) An authenticated user with permission to edit a page (with Twig processing enabled) in the Grav CMS admin console can inject malicious template directives to execute arbitrary OS commands on the remote web server.

For example, to exploit the vulnerability and execute the prohibited system('id') command, bypassing the sandbox, an editor could create/edit a web page with the following template directives:

twig {% set arr = {'1':'system', '2':'exec'} %} {{ vardump(grav.twig.twigvars['config'].set('system.twig.safefilters', arr)) }} {{ 'id'|system }} {{ 'whoami'|exec }}

Once the page is saved, it can be accessed by unauthenticated users, triggering the execution of the system('id') command on the server hosting the vulnerable Grav CMS.

Impact The vulnerability allows remote code execution on the underlying server, which could lead to full server compromise.

Other sources

Grav is a file-based Web platform. Prior to 1.8.0-beta.27, Grav CMS is vulnerable to a Server-Side Template Injection (SSTI) that allows any authenticated user with editor permissions to execute arbitrary code on the remote server, bypassing the existing security sandbox. Since the security sandbox does not fully protect the Twig object, it is possible to interact with it (e.g., call methods, read/write attributes) through maliciously crafted Twig template directives injected into a web page. This allows an authenticated editor to add arbitrary functions to the Twig attribute system.twig.safefilters, effectively bypassing the Grav CMS sandbox. This vulnerability is fixed in 1.8.0-beta.27.

MITRE

Affected Software

29 affected componentsFixes available
Grav Grav CMS<1.8.0-beta.27
composer/getgrav/grav<1.8.0-beta.27
1.8.0-beta.27
getgrav grav<1.8.0
getgrav grav=1.8.0-beta1
getgrav grav=1.8.0-beta10
getgrav grav=1.8.0-beta11
getgrav grav=1.8.0-beta12
getgrav grav=1.8.0-beta13
getgrav grav=1.8.0-beta14
getgrav grav=1.8.0-beta15
getgrav grav=1.8.0-beta16
getgrav grav=1.8.0-beta17
getgrav grav=1.8.0-beta18
getgrav grav=1.8.0-beta19
getgrav grav=1.8.0-beta2
getgrav grav=1.8.0-beta20
getgrav grav=1.8.0-beta21
getgrav grav=1.8.0-beta22
getgrav grav=1.8.0-beta23
getgrav grav=1.8.0-beta24
getgrav grav=1.8.0-beta25
getgrav grav=1.8.0-beta26
getgrav grav=1.8.0-beta3
getgrav grav=1.8.0-beta4
getgrav grav=1.8.0-beta5
getgrav grav=1.8.0-beta6
getgrav grav=1.8.0-beta7
getgrav grav=1.8.0-beta8
getgrav grav=1.8.0-beta9

Event History

Dec 1, 2025
CVE Published
via MITRE·09:15 PM
Data Sourced
via MITRE·09:15 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·10:15 PM
RemedyDescriptionSeverityWeaknessAffected Software
Dec 2, 2025
Advisory Published
via GitHub·12:36 AM
Data Sourced
via GitHub·12:36 AM
DescriptionSeverityWeaknessAffected Software
Free Weekly Intel

Don't miss critical vulnerabilities

Join thousands of security professionals who receive our weekly digest of trending CVEs, zero-days, and exploited vulnerabilities.

No spam. Unsubscribe anytime.

Frequently Asked Questions

1

What is the severity of CVE-2025-66299?

CVE-2025-66299 is considered critical due to its potential for arbitrary code execution by authenticated users with editor permissions.

2

How do I fix CVE-2025-66299?

To resolve CVE-2025-66299, upgrade to Grav CMS version 1.8.0-beta.27 or later.

3

Who is affected by CVE-2025-66299?

CVE-2025-66299 affects all versions of Grav CMS prior to 1.8.0-beta.27 that allow authenticated users with editor roles.

4

What type of vulnerability is CVE-2025-66299?

CVE-2025-66299 is classified as a Server-Side Template Injection (SSTI).

5

Can CVE-2025-66299 lead to data breaches?

Yes, CVE-2025-66299 can lead to serious data breaches as it allows attackers to execute arbitrary code on the server.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203