Server Side Template Injection (SSTI) via Twig escape handler
SummaryDue to the unrestricted access to twig extension class from grav context, an attacker can redefine the escape function and execute arbitrary commands.Detailshttps://github.com/twigphp/Twig/blob/3.x/src/Extension/EscaperExtension.php#L99Twig 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.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.PoCImpactTwig 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.