GHSA-W94C-JMG4-W4C9
grav-plugin-api PagesController::translate() persists page header and content without guardTwigContent, letting an api.pages.write key below admin.pages_twig enable Twig-in-content SSTI
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-W94C-JMG4-W4C9 divulgada · CVSS 8.1 (GitHub) | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Affected versions and vulnerable location
- Confirmed on grav-plugin-api at `bdca860` (tag 1.0.13).
- Vulnerable method: `classes/Api/Controllers/PagesController.php:1040` `translate()` (route `POST /pages/{route}/translate`).
- Caller-supplied fields read verbatim: `$body['content']` at `:1062` and `$body['header']` at `:1063`.
- Page built and saved: `:1086` `$translatedPage->header((object) $header)`, `:1087` `$translatedPage->rawMarkdown($content)`, `:1091` `$translatedPage->save()`.
- The only authorization is `requirePermission($request, self::PERMISSION_WRITE)` at `:1043` (that is `api.pages.write`).
- Guard that is missing here but present on the sibling write paths:
- `guardTwigContent()` defined at `classes/Api/Controllers/PagesController.php:2619`, called by `create()` at `:466` and `update()` at `:682`.
- `validatePageChanges()` (runs the editor XSS backstop) defined at `:2549`, called by `create()` at `:505` and `update()` at `:766`.
- `translate()` calls neither.
Attacker model
A holder of a Grav API key scoped to `api.pages.write` that does NOT carry the `admin.pages_twig` scope/permission. This is the delegated-least-privilege case the Twig-content gate exists to enforce: a page editor who may edit content but must not be able to turn on server-side Twig processing of page content.
The finding matters on the intended-secure configuration `security.twig_content.process_enabled: true` and `security.twig_content.editor_enabled: false`, which is exactly the config `guardTwigContent()` is written to police (see `:2641-2657`).
Why it is a bypass
`guardTwigContent()` blocks a write whenever the incoming or existing header sets `process.twig: true`, unless the caller satisfies both the scope cap and the permission:
// PagesController.php:2653-2657
if ($this->scopeAllows($request, 'admin.pages_twig')
&& ($this->isSuperAdmin($user) || $this->hasPermission($user, 'admin.pages_twig'))) {
return;
}
throw new TwigContentForbiddenException($reason);`create()` and `update()` invoke this before saving, so an `api.pages.write`-only key that submits `header: { process: { twig: true } }` is rejected with `REASON_FORBIDDEN`. `translate()` performs the same class of write, it creates a new language page file (`<template>.<lang>.md`) from a caller-supplied `header` and `content`, but never calls `guardTwigContent()`. The caller therefore persists a page whose frontmatter sets `process.twig: true` with an arbitrary Twig payload in the body, which Grav then evaluates through the Twig content processor at render time. That is the exact capability GHSA-96xv-p87j-58mx hardened on create/update; the translate endpoint was left out of the fix.
Because `validatePageChanges()` (which runs `Security::detectXssInEditorContent()`) is also skipped, this same path stores editor content without the render-time XSS screen, so assembled-markup stored XSS is not screened either.
Reachability trace verified on default branch
- `POST /pages/{route}/translate` with an `api.pages.write` key (no `admin.pages_twig`).
- `requirePermission(PERMISSION_WRITE)` passes (`:1043`).
- Body supplies `lang`, `content: "{{ <SSTI payload> }}"`, and `header: { process: { twig: true } }` (`:1061-1063`). The header is merged over blueprint defaults via `array_replace_recursive` (`:1069-1073`) but never filtered.
- `new Page()` -> `header((object) $header)` -> `rawMarkdown($content)` -> `save()` (`:1085-1091`). No `guardTwigContent`, no `validatePageChanges`.
- The translated page now carries `process.twig: true`; on render its body is evaluated by the Twig content processor inside the sandbox, giving sandboxed SSTI. Chained with any Twig-sandbox-escape gadget (the class Grav has patched repeatedly) this yields RCE, matching the impact rating of GHSA-96xv.
A closely related method, `sync()` at `:1342`, also omits both guards, but it copies header/content from an already-vetted on-disk source page rather than from the request body, so it cannot introduce new Twig and is not an injection path on its own. It should get the same guard in the fix for completeness, but it is not a standalone finding.
Reproduction
Executed end to end against a full Grav site (core 2.0.13 + admin/login/form/api plugins, PHP 8.5, `php -S`), `security.twig_content.process_enabled: true` and `editor_enabled: false`, using an API key scoped to `api.pages.write` ONLY (no `admin.pages_twig`):
POST /api/v1/pages/ssti/translate X-API-Key: <scoped key>
{"lang":"de","content":"SSTI-{{ 7*7 }}-END","header":{"process":{"twig":true}}}
=> HTTP 201 (process.twig:true persisted; user/pages/03.ssti/default.de.md written with process: {twig: true})
GET /de/ssti => HTTP 200
<div id="page-content"><p>SSTI-49-END</p></div> # {{ 7*7 }} executed -> 49
# Control: same scoped key on the gated create path
POST /api/v1/pages {...,"header":{"process":{"twig":true}}}
=> HTTP 403 {"title":"TWIG_CONTENT_FORBIDDEN","detail":"You don't have permission to enable Twig processing on pages."}The scoped key is rejected everywhere the gate runs (403 on create) and accepted only via `translate()`, where the rendered page evaluated `{{ 7*7 }}` to `49`. Source confirmation of the guard asymmetry:
rg -n "guardTwigContent|validatePageChanges|requirePermission\(\\\$request, self::PERMISSION_WRITE\)" \
classes/Api/Controllers/PagesController.phpObserved (abridged):
466: $this->guardTwigContent($request, null, $header); # create()
505: $this->validatePageChanges($page, ['header' => $header, 'content' => $content]);
682: $this->guardTwigContent($request, $page, (array) ($body['header'] ?? [])); # update()
766: $this->validatePageChanges($page, $body);
1043: $this->requirePermission($request, self::PERMISSION_WRITE); # translate(): WRITE only
# translate() body 1040-1094 contains no guardTwigContent and no validatePageChanges callSuggested fix
In `translate()` (and `sync()`), before building and saving the page, call the same two guards create/update use:
$this->guardTwigContent($request, null, is_array($body['header'] ?? null) ? $body['header'] : []);
// ... after assembling $header/$content:
$this->validatePageChanges($translatedPage, ['header' => $header, 'content' => $content]);so the Twig-content scope/permission cap and the editor XSS backstop apply uniformly across every page-write entry point.
Severity and CVSS reasoning
Suggested severity: High (same class as GHSA-96xv-p87j-58mx).
Suggested CVSS:3.1 vector: `CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H` (9.9) if the sandboxed SSTI is chained to code execution, or `S:U/C:H/I:H/A:N` (7.6) if scored as sandboxed template injection alone. I suggest High and defer the exact vector to the maintainer's rating of the sibling GHSA-96xv, since the reachable primitive (unprivileged enabling of `process.twig` with attacker content) is identical.
- `PR:L`: requires an `api.pages.write` key, but specifically one scoped BELOW the Twig-content capability.
- `C:H/I:H`: server-side template evaluation of attacker content; stored XSS also reachable via the skipped backstop.
How I found it and a note on tooling
I mapped every page-write entry point in `PagesController` and compared each against the two guards that create/update run. `create()` and `update()` call `guardTwigContent()` and `validatePageChanges()`; `translate()` and `sync()` call neither. I verified the guard body enforces the `admin.pages_twig` scope+permission cap and that `translate()` reads header/content straight from the request. I used AI assistance for enumeration and drafting and verified the cited lines at HEAD `bdca860`. I then executed the full chain against a live Grav site with a key scoped to `api.pages.write` only: the create path returned 403 TWIG_CONTENT_FORBIDDEN while `translate()` persisted `process.twig:true` with `{{ 7*7 }}` in the body, and the rendered page returned `SSTI-49-END`. Verification is executed end to end via HTTP.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
Packagistgetgrav/grav-plugin-api |
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-w94c-jmg4-w4c9Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
