GHSA-59QM-58V5-GVC5
Twig content sandbox escape: the `array` filter casts the DI container and exfiltrates the full site configuration
CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-59QM-58V5-GVC5 divulgada · CVSS 7.1 (GitHub) | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
Grav's Twig content sandbox is the boundary that lets a publisher write Twig inside page content without gaining operator capabilities. Part of that boundary is redacting the configuration tree, so sandboxed content cannot read plugin credentials, SMTP and OAuth secrets, Redis passwords, proxy URLs, or the `security.*` subtree.
The `array` cast is on the sandbox allowlist and is registered without the `needs_is_sandboxed` guard that `print_r`, `vardump`, `json_encode`, `yaml_encode` and `string` all carry. Its implementation calls `toArray()`, or falls back to `(array)`, entirely inside the filter, so the conversion never passes through the sandbox's member gate.
The `grav` Twig global is the raw dependency-injection container. Casting it with `grav|array` exposes Pimple's private `$values` array, which holds every resolved service including the un-redacted `Config` object. A second `array` cast on that object returns the whole configuration tree. Every secret the sandbox redaction exists to hide is disclosed, and the payload is stored in page content, so it renders for anonymous visitors.
Affected versions
Grav 2.0.0 through 2.0.24. The `array` filter has been registered without a sandbox guard since 2.0.0.
Grav 1.7 is not affected; it has no Twig content sandbox.
Details
Three things combine.
1. The cast is unguarded. The filter is registered with no options array, and so is the identical function form:
new TwigFilter('array', $this->arrayFilter(...)),
new TwigFunction('array', $this->arrayFilter(...)),
Contrast `print_r`, `yaml_encode`, `json_encode` and `string`, which each carry `['needs_environment' => true, 'needs_is_sandboxed' => true]` and route through `assertSandboxDumpSafe()`.
2. The conversion bypasses a deliberate denial. `arrayFilter()` calls `$input->toArray()` when the method exists, and `(array)$input` otherwise. Neither consults `GravSecurityPolicy::checkMethodAllowed()`. `SandboxDefaults` states plainly that `toarray` on a raw `Config` or `Data` object is deliberately absent from the method allowlist, a decision made for GHSA-j274-39qw-32c9 and GHSA-mc5q-6hpj-rp7j. The filter performs that denied call anyway.
3. The container is in scope and is not redacted. `GravExtension` returns `'grav' => $this->grav` as a Twig global. `Grav` extends `Grav\Framework\DI\Container`, which extends `Pimple\Container`, whose `$values` property is private. Pimple memoises resolved services back into `$values`, so `config` is a live `Config` instance by render time. `Twig::buildSandboxVars()` replaces the `config`, `system`, `site` and `theme` context variables with redacted versions, but it does not and cannot touch a Twig global.
Every direct route to the same data is correctly blocked by the sandbox, which is what makes this a protection-mechanism failure rather than a design gap. Verified against the per-source policy Grav actually uses in production:
{{ grav["config"]|array }} blocked SecurityNotAllowedPropertyError
{{ grav["config"]|yaml }} blocked SecurityNotAllowedPropertyError
{{ grav["config"]|json_encode }} blocked SecurityNotAllowedPropertyError
{{ grav["config"].get(...) }} blocked SecurityNotAllowedPropertyError
{{ grav|array }} allowed
Because the cast returns the whole container, this is a general service-disclosure primitive rather than a config-only one; any other resolved service is reachable the same way.
The `yaml` filter is likewise registered without the guard its `yaml_encode` twin carries. On its own it cannot leak an object, because Symfony's YAML dumper refuses object serialisation outright. It matters here only as a convenient printer for the plain array the `array` cast has already produced. It is being guarded in the same patch for consistency.
Impact
An account trusted only to author page content reads every operator secret in the configuration tree: plugin credentials such as mail transport passwords, payment, OAuth and API keys, and reCAPTCHA secrets; `system.http.proxy_url` and `system.gpm.proxy_url` including embedded credentials; `system.cache.redis.password`; and the whole `security.*` subtree. Those routinely enable lateral movement into mail relays, third-party APIs and Redis.
The payload is stored in page content and renders for every visitor, including anonymous ones, so the disclosure is not limited to the author's own session.
Two details make this reachable more widely than it first appears. Content Twig is on by default: the shipped `system/config/security.yaml` sets `twig_content.process_enabled: true` and `twig_sandbox.enabled: true`, with `twig_content.config_access: false` — precisely the "content Twig on, configuration hidden" posture this defeats. And a modular page's body Twig is processed unconditionally, independent of that gate and of the `admin.pages_twig` permission that `twig_content.editor_enabled` is meant to require. An author who can add a modular block reaches the sandboxed render without any Twig-specific permission.
Patches
Fixed in Grav 2.0.25.
The `array` filter and function, and the `yaml` filter, now resolve the calling template's sandbox state and consult the security policy before converting an object. Inside sandboxed content the cast is permitted only for non-objects, for `stdClass`, for an object whose `toArray()` the policy allows (the redacting `SandboxConfig` facade, `Uri`), and for an allow-listed `Iterator`. Anything else — the raw `Config` and the DI container included — raises a sandbox error, which soft-fails the render and writes to the security log like any other sandbox violation. Trusted templates on disk are unaffected.
A site that legitimately needs the cast on a particular class can re-add `toarray` for it under `security.twig_sandbox.allowed_methods`.
Workarounds
Upgrade to 2.0.25. There is no configuration-only workaround short of setting `security.twig_content.process_enabled: false`, which also disables Twig in content site-wide and does not stop modular pages.
Credits
Reported independently by @1diot9 and @AlpetGexha. Thank you both.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
Packagistgetgrav/grav |
Sin parche | — | — | — |
Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/getgrav/grav/security/advisories/GHSA-59qm-58v5-gvc5Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
