GHSA-PP89-H475-7GJ6
Editor-authored Twig can read a visiting admin's session cookie, and the shared page-content cache replays it to anonymous visitors
CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:U/C:H/I:H/A:H
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-PP89-H475-7GJ6 divulgada · CVSS 8 (GitHub) | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
Grav renders editor-authored Twig inside page content through a sandbox that permits `get_cookie()`, so a page can read any cookie sent with the current request — including the session cookie that authenticates the visitor. Grav then stores the finished, post-Twig output in a page-content cache keyed on page identity and the configuration checksum, with no session, user or request dimension, and no bypass for authenticated visitors.
An account holding only page-write permission can therefore publish a page that captures the session identifier of the next administrator who views it, and hand that identifier to an unauthenticated attacker on the following request. Replaying the cookie authenticates as that administrator.
Affected versions
- 2.0.19 through 2.0.24 — vulnerable in the shipped default configuration. Since 2.0.19 `security.twig_content.process_enabled` ships as `true`, and `Security::applyTwigContentDefault()` derives each page's `process.twig` flag from that gate when the page does not set one. Content Twig therefore runs on every page with no frontmatter and no operator action.
- 2.0.0 through 2.0.18, and 1.7.x — vulnerable only where content Twig has been explicitly enabled. Both `get_cookie()` and the session-blind cache long predate the gate; the 2.0.19 default is what made the combination reachable out of the box.
- Exploitation requires an authenticated account with page-write access in every version, which places 1.7 outside our backport scope. The fix lands on 2.0.
Details
Three behaviours combine.
1. Sandboxed page content may read arbitrary request cookies. `GravExtension` registers `get_cookie` and the implementation applies no name allowlist and no authorization check:
public function getCookie($key)
{
$cookie_value = filter_input(INPUT_COOKIE, $key);
if ($cookie_value === null) { return null; }
return htmlspecialchars(strip_tags($cookie_value), ENT_QUOTES, 'UTF-8');
}
`get_cookie` is allowlisted for sandboxed editor content in `SandboxDefaults::functions()`. The HTML escaping protects markup syntax; it does nothing for the secrecy or the replayability of a session identifier. Because the read happens server-side via `filter_input(INPUT_COOKIE, ...)`, the `HttpOnly`, `Secure` and `SameSite` attributes on the session cookie are all irrelevant.
2. Editor content reaches the sandbox with no frontmatter opt-in. Whether content Twig runs is decided by `Security::willProcessContentTwig()`, which ANDs the security gate with `$page->shouldProcess('twig')`. The second half is not the barrier it appears to be: `Page::__construct` seeds the process map through `Security::applyProcessDefaults()`, which calls `Security::applyTwigContentDefault()` and defaults `process.twig` to the gate's value when the page does not set it explicitly. On a default 2.0.19+ install, every page runs content Twig. The `twig_content.editor_enabled: false` control, which restricts the page editor's Twig toggle to holders of `admin.pages_twig`, is bypassed entirely because nothing needs toggling.
The payload also needs the site's session cookie name. `system.session` is not among the config subtrees redacted from sandboxed renders, so `system.session.name` yields the prefix, and `base_dir` is exposed to Twig as `GRAV_ROOT`, from which the uniqueness suffix is `substr(md5(GRAV_ROOT), 0, 7)`. Both `md5` and `slice` are allowlisted in the sandbox, so the page computes the cookie name itself with no prior knowledge of the install path.
3. The rendered output enters a cache shared by every visitor. `Page::content()` fetches before processing and stores after, and in the default ordering `cachePageContent()` runs *after* `processTwig()`, so it is the post-Twig string that is written. The key carries no request identity:
private function getPageContentCacheKey(Config $config): string
{
return $this->getCacheKey() . ':cfg=' . (string) $config->checksum();
}
`getCacheKey()` is the page id — path plus modification time. The Flex-pages render path is identical. The cache namespace itself is equally global: root URL, config key and Grav version. No session, user, cookie or request component participates anywhere, and nothing in core suppresses the page-content cache for an authenticated visitor.
Proof of concept
Create a public page through the page-write API as an account holding `api.access` and `api.pages.write` only — no `api.pages.read`, no `admin.*`, no super-admin:
POST /api/v1/pages
Authorization: Bearer LOW_WRITER_TOKEN
{"route":"/cookie-proof","title":"Cookie Proof",
"content":"COOKIE={{ get_cookie(system.session.name ~ \"-\" ~ ((base_dir|md5)|slice(0,7))) }}"}
The create returns `201 Created`. The body carries no `process.twig: true` frontmatter and does not need any. Then clear the cache, request `/cookie-proof` once as an administrator, request it again with no cookies, and replay the returned value against `GET /api/v1/users`.
The anonymous request returns the administrator's session value, and the replayed cookie authenticates as that administrator. The cookie captured is the unsuffixed frontend session cookie, which is precisely the credential the API accepts.
Timing. The capture happens only on the request that misses the cache, so an anonymous visitor arriving first refills the entry with an empty value. This is not a meaningful obstacle: the cache key includes the page's modification time, so the attacker invalidates the entry at will by re-saving the page, and can retry indefinitely.
Scope beyond `get_cookie`. `authorize` and `isajaxrequest` are likewise allowlisted for sandboxed content and likewise request-dependent. Content such as `{% if authorize('admin.super') %}...{% endif %}` renders per-visitor and is stored in the same session-blind cache, so an administrator's view of a page can be served to anonymous visitors. Removing `get_cookie` alone would not close this.
Save-time scanning does not catch it. `Security::detectXssInEditorContent()` renders the same sandboxed pass at save time and runs the XSS heuristics over the result. A captured session identifier is not XSS, so the save is accepted.
Impact
A low-privilege page writer obtains a valid authenticated administrator session identifier — not a reflected string, but a replayable credential — from any administrator who views one public page once. The attacker then retrieves it with no credentials at all and replays it to act with the administrator's permissions, including authenticated API access.
The only action required of the victim is a single ordinary page view. The victim pastes nothing, approves nothing, and runs no attacker-supplied code in their browser.
Patches
Fixed in Grav 2.0.25. Two changes:
- `get_cookie` is removed from the Twig content sandbox allowlist. Themes and plugins are unaffected — trusted templates are not sandboxed and continue to use `get_cookie` normally. A site that deliberately wants it back in page content can re-add it under `security.twig_sandbox.allowed_functions`, which is additive over the shipped defaults.
- Pages that render editor-authored content Twig are no longer stored post-Twig in the shared page-content cache. Both render paths now treat such pages as `never_cache_twig`: the markdown result is still cached, and the Twig pass is re-run on every request. Modular pages, whose Twig is theme-controlled rather than editor-authored, are unchanged.
Workarounds
Set either `security.twig_content.process_enabled: false` to close the content-Twig gate entirely, or `system.pages.never_cache_twig: true` to keep the gate open while preventing rendered Twig from entering the shared cache. Either one alone breaks the chain. Afterwards run `bin/grav clear` to discard already-poisoned entries, and rotate administrator sessions.
Credits
Reported by @canhieu, with a complete proof of concept, source-level analysis of the cache key, and independent reproduction across three environments.
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Desglose de métricas
Versiones afectadas
2.0.24Estado 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-pp89-h475-7gj6Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
