Safeguard
Vulnerability Analysis•

CVE-2026-46634: Twig template_from_string Sandbox Bypass

CVE-2026-46634 is a critical (9.8) sandbox policy bypass in Twig 3.9.0 to before 3.26.0. Upgrade to 3.26.0 and keep template_from_string out of sandboxes.

Safeguard Security Team
2 min read

CVE-2026-46634 is a protection mechanism failure in Twig, the PHP template language, scored CVSS 9.8. In certain sandbox setups, an inner template can run without security policy checks. Twig 3.26.0 is the fixed release, and you should also keep template_from_string out of any sandbox.

What's affected

The GitHub advisory GHSA-24x9-r6q4-q93w lists Twig from 3.9.0 up to, but not including, 3.26.0. The patched version is 3.26.0. Other branches are not listed in the advisory I read.

The condition is narrow. The sandbox must be enabled through a source policy, not globally, and a sandboxed template must be able to call template_from_string and include.

How to check if you're exposed

  1. Run composer show twig/twig to read your version.
  2. Search your code for SourcePolicyInterface or setSourcePolicy. If you never use a source policy sandbox, this issue does not apply in the way the advisory describes.
  3. Search for StringLoaderExtension and for template_from_string in your sandbox allowed functions list.

What to do now

  1. Upgrade twig/twig to 3.26.0 or later.
  2. Remove template_from_string from the sandbox's allowed functions.
  3. Per the advisory, the safest choice is not to register StringLoaderExtension at all when a sandbox is in use.
  4. Review which templates are treated as sandboxed and who can author them.

The advisory calls this a configuration trap and not a code bug. It says the 3.26.0 fix mainly adds documentation and warnings, so the workaround matters even after you upgrade.

Why it matters

The class is CWE-693, protection mechanism failure. Per the advisory, the inner template is compiled under a made up name, so a policy that decides by template name or path returns false for it, and the security check does nothing. A sandbox that quietly stops applying is worse than none, because people trust it.

The KEV flag is false and no exploitation is reported.

Quick check

Does upgrading alone close the gap?

The advisory says the fix adds documentation and warnings, and recommends the configuration workaround in any case. Do both.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.