Safeguard
Vulnerability Analysis•

CVE-2026-46633: Critical Code Injection in Twig

CVE-2026-46633 is a critical (9.8) code injection flaw in Twig before 3.26.0 via crafted template names. Upgrade twig/twig to 3.26.0 or later.

Safeguard Security Team
3 min read

CVE-2026-46633 is a critical code injection flaw in Twig, the PHP template language, scored CVSS 9.8. A crafted template name in a use tag can inject PHP into the compiled cache file. Twig 3.26.0 fixes it, so upgrade the twig/twig package to that version or later.

What's affected

The GitHub advisory GHSA-7p85-w9px-jpjp says Twig versions before 3.26.0 are affected, and that 3.26.0 is the patched release. The advisory does not list other branches, so I cannot confirm whether older release lines got a backport. Check the advisory if you run an older line.

Twig is pulled in by Symfony and many PHP frameworks and CMS products, so you may run it without having chosen it.

How to check if you're exposed

  1. In a Composer project, run composer show twig/twig and read the version.
  2. To see why it is installed, run composer why twig/twig.
  3. Check every PHP application on the host, including CMS plugins that vendor their own copy under a vendor directory.
  4. Ask whether any code builds Twig template names from user input or stored data. The advisory says the problem is in how a name from a use tag is written into the compiled cache file.

Version 3.26.0 or later is the fixed state.

What to do now

  1. Run composer update twig/twig and confirm the lock file shows 3.26.0 or later.
  2. Clear the compiled template cache so old generated files are rebuilt after the upgrade.
  3. Make sure the cache directory is writable only by the application user.
  4. Never let untrusted users supply template names or template source.
  5. Rebuild and redeploy containers that bake in vendor directories.

The advisory lists no workaround, so the upgrade is the fix.

Why it matters

The weakness is CWE-94, improper control of code generation. Twig compiles templates into PHP. The advisory says the string escaping helper handled double quotes but not single quotes, while the template name was placed inside a single quoted PHP string. A name with a single quote could end the string early and add PHP code, which runs when the cache file is first loaded.

The advisory also notes the security policy always allows the use tag, so sandboxed templates can reach this path. The KEV flag is false and no exploitation is reported.

Quick check

Does the Twig sandbox protect me?

The advisory says sandboxed templates can reach the affected code because the policy always allows the use tag. Upgrade rather than relying on the sandbox.

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.