llamaCVEVulnerability Intelligence
/
Advisory · GitHub · Packagist · getgrav/grav

GHSA-FG8G-663R-F366

Modular pages skip the save-time Twig XSS check, letting a page editor store render-time-assembled stored XSS (incomplete fix for GHSA-2c4f-86xc-cr74)

Texto original en inglés · Ver en español

Sin parche publicado
Descargar PNG JSON
CVSS
—
high
Fuente: —
ExplotaciónSin evidenciaNo figura en CISA KEV
Exploits públicos0Ninguno conocido
ParcheSin parcheEl fabricante no ha publicado corrección
Exposición93 dDesde la divulgación, 20 ago 2026, 7:54 a. m.
Detección90 dDesde la divulgación hasta su ingreso al índice
Decisión estimadaSeguir
Remediar en la ventana regular de mantenimiento
Estimación de Llama con el árbol SSVC de CISA a partir de la severidad declarada por GHSA (alta) y la evidencia de explotación (sin evaluación oficial): sin explotación conocida, no automatizable e impacto técnico parcial. No hay versión corregida: aplique mitigaciones.
Sospechosa como un adjunto llamado factura_final2.exe.Échale un ojo a tu inventario, ¿dale?
Timeline

Ciclo de vida de la vulnerabilidad

Hoy
Divulgación
Publicada
Explotación
Remediación
Monitoreo
Detectada +1
20 ago 26
18 nov 26
21 nov 26
20 ago 26
12 sept 26
6 oct 26
29 oct 26
21 nov 26
FechaFaseEventoDetalle
Divulgación Publicada GHSA-FG8G-663R-F366 divulgada
Monitoreo Detectada Ingresó al índice
Monitoreo Verificada Última verificación contra las fuentes
Resumen
Descripción del advisory
Texto original · GitHub · en inglés

Summary

Grav's save-time guard against render-time-assembled XSS in page content (`Security::detectXssInEditorContent()`, added for GHSA-2c4f-86xc-cr74) renders a page body through the sandboxed content-Twig pass and runs the XSS detector on the result, rejecting the save if a dangerous tag or event handler appears. It covers the blind spot of `Validation::checkSafety()`, which only inspects literal source and cannot see a handler assembled by Twig.

The save-time condition and the render-time condition disagreed. The render path (`Page.php:943`, `PageContentTrait.php:692`) computed `($content_twig_requested && $content_twig_allowed) || $this->modularTwig()`, so modular pages execute body Twig unconditionally, ignoring the `security.twig_content.process_enabled` gate. The save path (`Security.php:421`) returned early unless the gate was on and the page requested Twig, with no modular branch.

Because the gate ships off, modular pages executed Twig at render time while the save-time detection was skipped. Turning the gate on did not help either: a modular page rarely sets `process: twig` in its own header, so `shouldProcess('twig')` was false and the guard bailed out regardless. There was no configuration in which modular content was scanned.

A user whose account has page-edit rights but is not covered by `security.xss_whitelist` (default `admin.super`) could therefore store a Twig-assembled XSS payload that runs for visitors to the page embedding the module. Modular status comes from a slug prefix the author chooses, so no additional privilege is involved.

Affected versions

  • `getgrav/grav` (Composer, self-hosted PHP) — >= 2.0.0, <= 2.0.17.
  • The content-Twig gate arrived in 2.0.0-rc.4. The save-time guard replaced an earlier render-time output scan in 2.0.11, but that earlier scan used the same gate-only condition (`$scan_twig_xss = $content_twig_requested && $content_twig_allowed`), so modular pages were never covered on any 2.0 release. 2.0.11 is not a regression point.
  • Grav 1.7 is not affected by this asymmetry: it has neither the gate nor the guard, and its content-Twig posture is covered by GHSA-2c4f-86xc-cr74.

Details

Root cause: asymmetric decisions between save-time validation and render-time execution.

Save-time guard — `system/src/Grav/Common/Security.php:421`, in `Security::detectXssInEditorContent()`:

// Only content that Twig will actually process at render time can carry a
// render-time-assembled payload. If the content-Twig gate is off, or this
// page doesn't request Twig, the raw-source validator already covers it.
if (!$config->get('security.twig_content.process_enabled', false) || !$page->shouldProcess('twig')) {
    return null;
}

No modular branch, so with the shipped default (`process_enabled: false`) this always returned early for a module.

Render-time sink — `system/src/Grav/Common/Page/Page.php:943`:

$process_twig = ($content_twig_requested && $content_twig_allowed) || $this->modularTwig();

The `modularTwig()` short-circuit runs editor Twig regardless of the gate, and the comment above it defers XSS enforcement to save time — the very check that was skipped. `system/src/Grav/Framework/Flex/Pages/Traits/PageContentTrait.php:692` carries the identical branch with `isModule()`, so both page engines were affected, and `system/src/Grav/Common/Twig/Twig.php:409` reflects the same decision one layer down.

Entry point — `Page.php:231` sets `$this->modularTwig(str_starts_with($this->slug(), '_'));`; the Flex engine falls back to the same test at `PageLegacyTrait.php:846`. Creating such a page is a supported product feature rather than a trick: the API plugin's `POST /api/pages` accepts `kind: "module"` and adds the `_` prefix itself (`PagesController.php:425`), gated only on `api.pages.write` plus the parent page's `create` rule, and the admin exposes the same thing as "Add Modular". No code path strips or rejects a leading underscore.

Chain — `Page::save()` (`Page.php:1359`) and `PageObject::onBeforeSave()` (`PageObject.php:194`) are the two save paths and both relied solely on `detectXssInEditorContent()`. `Validation::checkSafety()` runs `detectXss()` on literal source only; the `on_events` and `dangerous_tags` patterns match formed `on*=` attributes and `<tag` sequences, so a token split across a Twig concatenation does not match.

Verified proof of concept

Reproduced against a real Grav instance (PHP 8.5, stock `system/config/security.yaml`), acting as a non-super user with page-edit rights, comparing the fixed and unfixed trees directly.

  1. Create a normal page at `/landing` whose header contains `content: { items: '@self.modular' }` — the standard modular layout.
  2. Create a module beneath it (folder `_evil`) with a body such as:

```twig
{% autoescape false %}{{ "<img src=x on" ~ "error=alert(1)>" }}{% endautoescape %}
```

or, equivalently:

```twig
{{ ("<img src=x on" ~ "error=alert(1)>")|markdown }}
```

Before the fix the save succeeded: `Security::detectXss()` on the raw source returns `null`, and `detectXssInEditorContent()` returned `null` because of the early return above. After the fix the save is rejected with `on_events`.
3. Request `/landing` as an anonymous visitor. The response contains `<img src=x onerror=alert(1)>` as live markup.
4. Control: the identical body on a non-modular page renders as inert literal text, because `$process_twig` is false — confirming the exposure comes specifically from the modular short-circuit.

Three clarifications versus the original report, all established by running the code rather than reading it:

  • Whether the payload reaches the browser depends on the theme's modular template. A template that emits `{{ content|raw }}` — which core's own fallback `system/templates/modular/default.html.twig` does, as do several of Quark 2's modular templates — renders it live. A template that emits `{{ content }}` escapes it. So exploitability is real but theme-dependent, and any site whose modular templates use `|raw` is exposed.
  • The report's example payload is not the right proof of concept. `<img src=x {{ "on" ~ "error" }}=alert(1)>` does produce a live handler through Twig alone — Twig autoescape does not defuse it, because the `{{ }}` output is the bare string `onerror`, which has nothing to escape. It nevertheless fails to fire at render, because Grav runs markdown before Twig by default (`system.pages.twig_first: false`) and Parsedown escapes the malformed tag. A working payload has to defeat escaping after markdown, which `{% autoescape false %}` (an allow-listed tag) and the `markdown` filter both do. The save-time guard rejects all three forms, so it is strictly more conservative than the render — the correct direction.
  • Modular pages are not reachable at their own URL. `Page::modularTwig()` clears `routable`, so requesting the module directly returns 404. The payload reaches visitors through the parent page that embeds it, which is the ordinary way modular pages are published.

Impact

Stored XSS across an explicit privilege boundary. Grav treats content editors and administrators as separate trust tiers: `security.xss_whitelist` (default `admin.super`) limits storing literal dangerous markup to super administrators, and the GHSA-2c4f-86xc-cr74 guard exists to stop lower-privileged users assembling the equivalent through Twig. On modular pages that boundary did not hold, in any configuration.

Any account with page-edit rights could implant persistent JavaScript that runs for visitors to the embedding page, including administrators browsing the site, where it can act inside the administrator's session. Rated High under Grav's trust-boundary policy: a lower-privilege actor's stored content runs in a higher-privilege session.

Patches

Fixed in Grav 2.0.18.

The render-time decision is extracted into `Security::willProcessContentTwig(PageInterface $page): bool` and used by all three call sites — `Page::content()`, `PageContentTrait::processContent()` and `detectXssInEditorContent()` — so the save-time check and the render can no longer diverge. `isModule()` is declared on `PageContentInterface`, so both page engines satisfy it without a `method_exists()` guard.

The save-time scan additionally renders the module body without its modular theme template (`Twig::processPage()` gained a `$moduleTemplate` flag, defaulting to true so existing callers are unaffected). Without that, a theme whose own modular wrapper contains an inline event handler would fail otherwise clean saves — confirmed against a wrapper containing `onclick=`.

The check is enforced at save, so content stored before upgrading is not retroactively scanned. Operators who allow non-super users to edit pages should review existing modular content.

Workaround for unpatched installs: restrict page-edit permissions to trusted accounts, or ensure modular templates emit `{{ content }}` rather than `{{ content|raw }}`.

Credits

Reported by @TWPaMWang https://github.com/TWPaMWang, who identified the mismatch between the save-time and render-time conditions and its consequence for modular pages.

Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.

Versiones

Rangos afectados

Afectada Corregida
getgrav/grav≥ 2.0.0 ≤ 2.0.17
2.0.0
2.0.17
Remediación

Estado del parche por paquete

Paquete / productoEstadoCorregida enDesde divulgaciónÚltima versión
Packagistgetgrav/grav
Sin parche — — —
Explotación

Arsenal público

Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.

Referencias
Advisoryhttps://github.com/getgrav/grav/security/advisories/GHSA-fg8g-663r-f366

Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.