CVE-2026-46638
JSON

6.0medium

Twig: `{% sandbox %}{% include %}` skips checkSecurity() on cached templates (incomplete fix for CVE-2024-45411)

Severity
6.0medium CVSS:4.0 by GitHub_M
Exploit likelihood
0.27% (higher than 19% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
GitHub_M
Also known as
GHSA-7fxw-r6jv-74c8

Description

Twig is a template language for PHP. Prior to 3.26.0, {% sandbox %}{% include %} can include a template that was previously loaded outside the sandbox without re-invoking checkSecurity(), allowing the cached template to use tags, filters, and functions that should have been denied by SecurityPolicy::checkSecurity(). This issue is fixed in version 3.26.0.

Affected

Product or packageVersionsReported by
twigphp Twig< 3.26.0CVE List
twig/twig (Packagist)before 3.26.0GitHub Advisory Database
symfony twigbefore 3.26.0NVD

All scores

GitHub_M6.0medium CVSS:4.0CVSS:4.0/AV:N/AC:L/AT:P/PR:L/UI:N/VC:H/VI:L/VA:N/SC:N/SI:N/SA:N
GitHubmedium CVSS:4.0CVSS:4.0/AV:N/AC:L/AT:P/PR:L/UI:N/VC:N/VI:N/VA:N/SC:H/SI:H/SA:H
NVD8.1high CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N

Classification

CWE-693

SSVC (CISA-ADP): exploitation none, automatable no, technical impact partial.

What each source says

CVE List

Twig is a template language for PHP. Prior to 3.26.0, {% sandbox %}{% include %} can include a template that was previously loaded outside the sandbox without re-invoking checkSecurity(), allowing the cached template to use tags, filters, and functions that should have been denied by SecurityPolicy::checkSecurity(). This issue is fixed in version 3.26.0.

GitHub Advisory Database
Description

The fix for CVE-2024-45411 / GHSA-6j75-5wfj-gh66 added an explicit $loaded->unwrap()->checkSecurity() call in CoreExtension::include() so that a template already cached in Environment::$loadedTemplates is re-checked when included with sandboxed = true.

The deprecated but still functional {% sandbox %}{% include ... %}{% endsandbox %} tag path was not updated: it compiles to enableSandbox(); yield from $this->load(...)->unwrap()->yield(...); disableSandbox(); with no checkSecurity() re-invocation. If the included template was loaded once outside the sandbox in the same Environment instance, its constructor (and therefore its compiled checkSecurity() call) already ran while isSandboxed() was false, so the tags/filters/functions allowlist enforced by SecurityPolicy::checkSecurity() is never applied.

An attacker who can author the included template gains access to every filter, function and tag registered in the environment, regardless of the sandbox policy.

Resolution

The compiled output of {% sandbox %}{% include %} now calls checkSecurity() on the loaded template, matching the behaviour of CoreExtension::include() with sandboxed = true.

Credits

Twig would like to thank Claude Mythos Preview (via Project Glasswing) for reporting the issue and providing the fix.

NVD (es)

Twig es un lenguaje de plantillas para PHP. Antes de la versión 3.26.0, {% sandbox %}{% include %} puede incluir una plantilla que fue cargada previamente fuera del sandbox sin volver a invocar checkSecurity(), permitiendo que la plantilla en caché use etiquetas, filtros y funciones que deberían haber sido denegados por SecurityPolicy::checkSecurity(). Este problema está solucionado en la versión 3.26.0.

References

Sources

SourceRecordLicence
CVE ListCVE-2026-46638 changed 2026-07-15CVE Terms of Use
GitHub Advisory DatabaseGHSA-7fxw-r6jv-74c8 changed 2026-09-10CC-BY-4.0
NVDCVE-2026-46638 changed 2026-10-24Public domain