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

Published May 21, 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

Twig is a template language for PHP. 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

2 affected componentsFixes available
composer/twig/twig<3.26.0
3.26.0
Symfony Twig<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 (Twig template engine for PHP) to a version that resolves this vulnerability.

    Fixed in 3.26.0
  3. Configuration

    Update Twig so Compiler::string() escapes single quotes when template names (from `{% use %}` tags) are embedded inside surrounding PHP single-quoted string literals, preventing breakout into the compiled cache file.

    Twig Compiler::string() escaping of single quotes in generated PHP single-quoted string literals = escape single quotes (')

Event History

May 21, 2026
Advisory Published
via GitHub·09:24 PM
Data Sourced
via GitHub·09:24 PM
DescriptionWeaknessAffected 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
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-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