CVE-2026-46634
JSON

7.7high

Twig: `template_from_string()` escapes a SourcePolicy-driven sandbox via synthesized template name

Severity
7.7high CVSS:4.0 by GitHub_M
Exploit likelihood
0.51% (higher than 45% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
GitHub_M
Also known as
GHSA-24x9-r6q4-q93w

Description

Twig is a template language for PHP. From 3.9.0 until 3.26.0, template_from_string() compiles an inner template under a synthesized __string_template__<hash> name that can fall outside a SourcePolicyInterface sandbox decision, allowing a sandboxed template that can call template_from_string and include to render an inner template without security policy enforcement. This issue is fixed in version 3.26.0.

Affected

Product or packageVersionsReported by
twigphp Twig>= 3.9.0, < 3.26.0CVE List
twig/twig (Packagist)from 3.9.0 before 3.26.0GitHub Advisory Database
symfony twigfrom 3.9.0 before 3.26.0NVD

All scores

GitHub_M7.7high CVSS:4.0CVSS:4.0/AV:N/AC:L/AT:P/PR:L/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N
GitHubmedium rating
NVD9.8critical CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H

Classification

CWE-693

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

What each source says

CVE List

Twig is a template language for PHP. From 3.9.0 until 3.26.0, template_from_string() compiles an inner template under a synthesized __string_template__<hash> name that can fall outside a SourcePolicyInterface sandbox decision, allowing a sandboxed template that can call template_from_string and include to render an inner template without security policy enforcement. This issue is fixed in version 3.26.0.

GitHub Advisory Database
Description

When the sandbox is enabled selectively via SourcePolicyInterface (and not globally), a sandboxed template that is allowed to call template_from_string and include can render an arbitrary inner template with no security policy enforcement.

Environment::createTemplate() compiles the inner string under a synthesized name (__string_template__<hash>), so a name/path-based SourcePolicy returns false for it, and the inner template's checkSecurity() becomes a no-op. From a template the integrator believes is sandboxed, an attacker can use any tag/filter/function (including constant() to read secrets, or |map("system") to execute shell commands).

Resolution

This is a configuration trap rather than a code bug: there is no legitimate use case for exposing template_from_string to untrusted template authors, and propagating the parent sandbox state through template_from_string would require invasive changes to SourcePolicyInterface semantics with their own risks.

Starting with Twig 3.26.0, the documentation and the PHPDoc of StringLoaderExtension::templateFromString() explicitly warn against allowing template_from_string in a sandboxed environment (i.e. listing it in a SecurityPolicy allowed-functions list). Integrators using a SourcePolicyInterface MUST NOT allow template_from_string in their allowed functions; the safest option is not to register StringLoaderExtension at all when a sandbox is in use.

Credits

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

NVD (es)

Twig es un lenguaje de plantillas para PHP. Desde la versión 3.9.0 hasta la 3.26.0, template_from_string() compila una plantilla interna bajo un nombre sintetizado __string_template__[hash] que puede quedar fuera de una decisión de sandbox de SourcePolicyInterface, permitiendo que una plantilla en sandbox que puede llamar a template_from_string e include renderice una plantilla interna sin la aplicación de la política de seguridad. Este problema está solucionado en la versión 3.26.0.

References

Sources

SourceRecordLicence
CVE ListCVE-2026-46634 changed 2026-07-29CVE Terms of Use
GitHub Advisory DatabaseGHSA-24x9-r6q4-q93w changed 2026-09-10CC-BY-4.0
NVDCVE-2026-46634 changed 2026-10-24Public domain