Twig CVE-2026-46640
HIGHSeverity by source
CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X
Primary rating from Vendor (https://github.com/twigphp/Twig) · only source for this CVE.
CVSS VectorVendor: https://github.com/twigphp/Twig
CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X
Lifecycle Timeline
4DescriptionCVE.org
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.
AnalysisAI
Arbitrary PHP code execution in Twig templating engine versions 3.15.0 through 3.25.x allows attackers who control template source to inject raw PHP into the compiled template via the _self.(<string>) dynamic-attribute macro-reference path, fully bypassing the SandboxExtension. The flaw executes injected code at template-load time, before any SecurityPolicy check runs, rendering even a globally-enabled empty allowlist sandbox ineffective. No public exploit identified at time of analysis, but the vendor advisory describes the bypass mechanism in enough detail that PoC development is straightforward.
Technical ContextAI
Twig is the most widely deployed PHP templating engine, embedded in Symfony, Drupal, Shopware, Ibexa, and thousands of CMS/SaaS stacks via the composer/twig/twig package. The vulnerability lives in DotExpressionParser handling of the obj.(expr) dynamic-attribute syntax introduced in 3.15.0 to replace the deprecated attribute() function. When the receiver is _self or an {% import %} alias and the parenthesised expression is a string literal, the parser shortcuts into the macro-call path and concatenates the attacker-supplied string into a MacroReferenceExpression name without identifier validation. MacroReferenceExpression::compile() then emits that string raw into the generated PHP source file Twig writes to its cache, so when PHP includes the compiled template the attacker's code runs natively. This is a classic CWE-94 Improper Control of Generation of Code (code injection) caused by failure to validate/escape an identifier before string-interpolating it into emitted source.
RemediationAI
Vendor-released patch: upgrade twig/twig to 3.26.0, which validates that the dynamic attribute resolves to a valid macro identifier before routing through MacroReferenceExpression and emits the macro name through a properly escaped compile path. Update via composer update twig/twig and verify the resolved version is >= 3.26.0; downstream framework users should also pick up the matching Symfony/Drupal/Shopware security release referenced at https://symfony.com/cve-2026-46640 and https://github.com/twigphp/Twig/security/advisories/GHSA-45vw-wh46-2vx8. If patching is blocked, the only effective compensating control is to ensure no untrusted party can supply or influence Twig template source - disable any user-facing template editors, do not pass user input into Twig\Environment::createTemplate() or string loaders, and audit any custom loader that reads templates from databases or uploads; note that relying on SandboxExtension with a restrictive SecurityPolicy is NOT a valid workaround because this vulnerability executes before checkSecurity() is called. A more invasive workaround is to lint/strip incoming templates for the _self.(...) and <alias>.(...) patterns (with the alias being any {% import %} name), which can break legitimate macro usage in tenants that rely on dynamic macro dispatch.
sapi/cgi/cgi_main.c in PHP before 5.3.12 and 5.4.x before 5.4.2, when configured as a CGI script (aka php-cgi), does not
(1) boardData102.php, (2) boardData103.php, (3) boardDataJP.php, (4) boardDataNA.php, and (5) boardDataWW.php in Netgear
ProjectSend versions prior to r1720 are affected by an improper authentication vulnerability. Rated critical severity (C
Roundcube Webmail contains a critical PHP object deserialization vulnerability (CVE-2025-49113, CVSS 9.9) that allows au
Util/PHP/eval-stdin.php in PHPUnit before 4.8.28 and 5.x before 5.6.3 allows remote attackers to execute arbitrary PHP c
Palo Alto Networks PAN-OS management web interface contains an authentication bypass allowing unauthenticated attackers
Nagios XI version xi-5.7.5 is affected by OS command injection. Rated high severity (CVSS 8.8), this vulnerability is re
Nagios XI version xi-5.7.5 is affected by OS command injection. Rated high severity (CVSS 8.8), this vulnerability is re
The get_referers function in /opt/ws/bin/sblistpack in Sophos Web Appliance before 3.7.9.1 and 3.8 before 3.8.1.1 allows
The Backup Migration plugin for WordPress is vulnerable to Remote Code Execution in all versions up to, and including, 1
NetAlertX (formerly PiAlert) versions 23.01.14 through 24.x before 24.10.12 allow unauthenticated command injection thro
The GiveWP - Donation Plugin and Fundraising Platform plugin for WordPress is vulnerable to PHP Object Injection in all
Same weakness CWE-94 – Code Injection
View allSame technique Code Injection
View allShare
External POC / Exploit Code
Leaving vuln.today
GHSA-45vw-wh46-2vx8