CVE-2026-46633: PHP code injection via `{% use %}` template name

Published May 20, 2026
·
Updated

Description

Compiler::string() escapes ", $, \, NUL and TAB when generating PHP double-quoted string literals, but does not escape single quotes. In ModuleNode::compileConstructor(), the template name from a {% use %} tag is compiled via subcompile() -> string() and placed inside a surrounding PHP single-quoted string literal. A template name containing a single quote terminates that surrounding string early, allowing arbitrary PHP expressions to be injected into the compiled cache file.

The injected code executes within the PHP process when the cache file is first loaded, bypassing the Twig sandbox entirely and achieving remote code execution. SecurityPolicy unconditionally allows {% use %} regardless of the configured allowedTags, so this primitive is reachable from sandboxed templates as well.

Resolution

Compiler::string() now also escapes single quotes so that template names placed inside single-quoted PHP literals can no longer break out of the surrounding context.

Credits

Twig would like to thank Anvil Secure in collaboration with Claude and Anthropic Research for reporting the issue and providing the fix.

Other sources

PHP code injection via {% use %} template name

— Packagist

Twig is a template language for PHP. Starting in 1.15.1 and prior to 3.26.0, Compiler::string() does not escape single quotes when a template name from a {% use %} tag is placed inside a PHP single-quoted string literal, allowing a crafted template name to terminate the string and inject arbitrary PHP expressions into the compiled cache file. This issue is fixed in version 3.26.0.

— MITRE

Affected Software

16 affected componentsFixes available
composer/twig/twig<3.26.0
3.26.0
composer/twig/twig>=1.0.0, <2.0.0
composer/twig/twig>=2.0.0, <3.0.0
composer/twig/twig>=3.0.0, <3.26.0
3.26.0
Symfony Twig<3.26.0
debian/php-twig
3.5.1-1+deb12u33.27.0-0+deb13u13.30.0-1
composer/twig/twig>=1.15.1<3.26.0
3.26.0
debian/php-twig<3.5.1-1+deb12u3
3.5.1-1+deb12u3
debian/php-twig<3.27.0-0+deb13u1
3.27.0-0+deb13u1
debian/php-twig<3.26.0-1
3.26.0-1
ubuntu/php-twig*
ubuntu/php-twig*
ubuntu/php-twig*
ubuntu/php-twig*
ubuntu/php-twig*
ubuntu/php-twig*

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 debian/php-twig to a version that resolves this vulnerability.

    Fixed in 3.5.1-1+deb12u3Fixed in 3.27.0-0+deb13u1Fixed in 3.30.0-1
  3. Upgrade

    Upgrade debian/php-twig to a version that resolves this vulnerability.

    Fixed in 3.5.1-1+deb12u3
  4. Upgrade

    Upgrade debian/php-twig to a version that resolves this vulnerability.

    Fixed in 3.27.0-0+deb13u1
  5. Upgrade

    Upgrade debian/php-twig to a version that resolves this vulnerability.

    Fixed in 3.26.0-1
  6. Upgrade

    Upgrade to a fixed release to a version that resolves this vulnerability.

    Fixed in 3.26.0

Event History

May 20, 2026
Advisory Published
via Packagist·08:00 AM
Data Sourced
via Packagist·08:00 AM
DescriptionSeverityAffected Software
May 21, 2026
Advisory Published
via GitHub·09:24 PM
Data Sourced
via GitHub·09:24 PM
DescriptionWeaknessAffected Software
Data Sourced
via OSV·09:24 PM
DescriptionSeverityWeaknessAffected Software
Jul 14, 2026
CVE Published
via MITRE·09:14 PM
Data Sourced
via MITRE·09:14 PM
DescriptionWeakness
Data Sourced
via NVD·10:16 PM
RemedyDescriptionSeverityWeaknessAffected Software

Parent advisories

This vulnerability appears in the following advisories.

Frequently Asked Questions

1

What is the severity of CVE-2026-46633?

CVE-2026-46633 has a high severity rating of 8.7.

2

How do I fix CVE-2026-46633?

To fix CVE-2026-46633, update the Twig library to the latest version provided by the maintainers.

3

What type of vulnerability is CVE-2026-46633?

CVE-2026-46633 is classified as a Code Injection vulnerability.

4

Which software is affected by CVE-2026-46633?

CVE-2026-46633 affects the Composer Twig library and Symfony Twig.

5

What component of Twig is vulnerable in CVE-2026-46633?

The vulnerability occurs in the handling of template names within the `{% use %}` tag in Twig.

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