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

Published May 21, 2026
·
Updated

Description

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

Environment::createTemplate() compiles the inner string under a synthesized name (stringtemplate<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 templatefromstring to untrusted template authors, and propagating the parent sandbox state through templatefromstring 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 templatefromstring in a sandboxed environment (i.e. listing it in a SecurityPolicy allowed-functions list). Integrators using a SourcePolicyInterface MUST NOT allow templatefromstring 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.

Other sources

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

MITRE

Affected Software

2 affected componentsFixes available
composer/twig/twig>=3.9.0<3.26.0
3.26.0
Symfony Twig>=3.9.0<3.26.0

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade composer/twig/twig to a version that resolves this vulnerability.

    Fixed in 3.26.0
  2. Upgrade

    Upgrade Twig to a version that resolves this vulnerability.

    Fixed in 3.26.0
  3. Configuration

    If using SourcePolicyInterface sandboxing, do not allow `template_from_string` in the sandbox allowed-functions list; the safest option is not to register `StringLoaderExtension` at all when a sandbox is in use.

    Twig SourcePolicyInterface sandbox (allowed functions) template_from_string = disallow

Event History

May 21, 2026
Advisory Published
via GitHub·09:25 PM
Data Sourced
via GitHub·09:25 PM
DescriptionWeaknessAffected Software
Jul 14, 2026
CVE Published
via MITRE·09:19 PM
Data Sourced
via MITRE·09:19 PM
DescriptionWeakness
Data Sourced
via NVD·10:16 PM
RemedyDescriptionSeverityWeaknessAffected Software
Free Weekly Intel

Don't miss critical vulnerabilities

Join thousands of security professionals who receive our weekly digest of trending CVEs, zero-days, and exploited vulnerabilities.

No spam. Unsubscribe anytime.

Frequently Asked Questions

1

What is the severity of CVE-2026-46634?

The severity of CVE-2026-46634 is rated at 75.

2

How do I fix CVE-2026-46634?

To fix CVE-2026-46634, ensure that the sandbox is globally enforced rather than selectively via SourcePolicyInterface.

3

What software is affected by CVE-2026-46634?

CVE-2026-46634 affects the composer/twig/twig software.

4

What does CVE-2026-46634 exploit?

CVE-2026-46634 exploits a vulnerability where a sandboxed template can render an arbitrary inner template without security policy enforcement.

5

When was CVE-2026-46634 published?

CVE-2026-46634 was published on May 21, 2026.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203