CVE-2026-46640: Twig: Arbitrary PHP code execution via `_self.(<string>)` macro-reference compilation

Published May 21, 2026
·
Updated

Description

The obj.(expr) dynamic-attribute syntax (added in 3.15.0 as the replacement for the deprecated attribute() function) lets the attribute be an arbitrary expression. When the receiver is self (or any {% import %} alias) and the parenthesised expression is a string literal, DotExpressionParser short-circuits to the macro-call path and concatenates the attacker-controlled string into a MacroReferenceExpression name with no identifier validation. MacroReferenceExpression::compile() then emits that name raw into the generated PHP source.

An attacker who can supply template source can inject arbitrary PHP into the compiled template and execute it at template-load time, before checkSecurity() is ever called. This is a complete bypass of SandboxExtension, including a globally-enabled sandbox with an empty SecurityPolicy allowlist.

Resolution

The parser now validates that the dynamic attribute resolves to a valid macro identifier before routing through MacroReferenceExpression, and the macro-reference compiler emits the name through a properly escaped path.

Credits

Twig would like to thank Claude Mythos Preview (via Project Glasswing) for reporting the issue and providing the fix.

Other sources

Twig is a template language for PHP. From 3.15.0 until 3.26.0, self.(<string>) and import-alias dynamic attribute syntax can concatenate an attacker-controlled string into a MacroReferenceExpression name without identifier validation, causing raw PHP to be emitted into the generated template source and executed at template-load time. This issue is fixed in version 3.26.0.

MITRE

Affected Software

2 affected componentsFixes available
composer/twig/twig>=3.15.0<3.26.0
3.26.0
Symfony Twig>=3.15.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 to a fixed release to a version that resolves this vulnerability.

    Fixed in 3.26.0
  3. Compensating control

    Until you can upgrade, avoid allowing attackers to supply template source that can use Twig macro-reference compilation involving `_self.(<string>)` / import-alias dynamic attribute syntax, since injected arbitrary PHP can execute at template-load time before `checkSecurity()` is called.

Event History

May 21, 2026
Advisory Published
via GitHub·09:31 PM
Data Sourced
via GitHub·09:31 PM
DescriptionWeaknessAffected Software
Jul 14, 2026
CVE Published
via MITRE·09:22 PM
Data Sourced
via MITRE·09:22 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-46640?

CVE-2026-46640 has a risk score of 85, indicating a high severity level.

2

What type of vulnerability is CVE-2026-46640?

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

3

How do I fix CVE-2026-46640?

To mitigate CVE-2026-46640, ensure you are using a version of Twig that is updated to resolve this vulnerability.

4

What software is affected by CVE-2026-46640?

CVE-2026-46640 affects the composer/twig/twig library starting from version 3.15.0.

5

What are the implications of exploiting CVE-2026-46640?

Exploiting CVE-2026-46640 can lead to unauthorized code execution due to the dynamic attribute syntax allowing arbitrary expressions.

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