<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Twig (&gt;= 3.15.0, &lt; 3.26.0) — CraftedSignal Threat Feed</title><link>https://feed.craftedsignal.io/products/twig--3.15.0--3.26.0/</link><description>Trending threats, MITRE ATT&amp;CK coverage, and detection metadata. Fed continuously.</description><generator>Hugo</generator><language>en</language><managingEditor>hello@craftedsignal.io</managingEditor><webMaster>hello@craftedsignal.io</webMaster><lastBuildDate>Thu, 21 May 2026 21:32:18 +0000</lastBuildDate><atom:link href="https://feed.craftedsignal.io/products/twig--3.15.0--3.26.0/feed.xml" rel="self" type="application/rss+xml"/><item><title>Twig RCE via Macro-Reference Compilation (CVE-2026-46640)</title><link>https://feed.craftedsignal.io/briefs/2026-05-twig-rce/</link><pubDate>Thu, 21 May 2026 21:32:18 +0000</pubDate><author>hello@craftedsignal.io</author><guid isPermaLink="true">https://feed.craftedsignal.io/briefs/2026-05-twig-rce/</guid><description>A vulnerability in Twig versions 3.15.0 to 3.26.0 (CVE-2026-46640) allows arbitrary PHP code execution via the `_self.(&lt;string&gt;)` macro-reference compilation, enabling attackers to inject and execute arbitrary PHP code by supplying malicious template source, bypassing the SandboxExtension.</description><content:encoded><![CDATA[<p>A critical security flaw exists in Twig, a templating engine for PHP, specifically affecting versions 3.15.0 up to (but not including) 3.26.0. The vulnerability, identified as CVE-2026-46640, stems from the <code>obj.(expr)</code> dynamic-attribute syntax, which was introduced in version 3.15.0 as a replacement for the deprecated <code>attribute()</code> function. When the receiver is <code>_self</code> or an imported alias, and the expression is a string literal, the <code>DotExpressionParser</code> incorrectly concatenates the attacker-controlled string into a <code>MacroReferenceExpression</code> without proper validation. This bypasses the <code>SandboxExtension</code>, even with a globally-enabled sandbox and an empty <code>SecurityPolicy</code> allowlist. An attacker who can control the template source can inject arbitrary PHP code into the compiled template, resulting in code execution at template-load time.</p>
<h2 id="attack-chain">Attack Chain</h2>
<ol>
<li>The attacker gains the ability to supply template source code to the Twig engine. This could be achieved through methods like exploiting an existing file upload vulnerability or directly manipulating template files if access is available.</li>
<li>The attacker crafts a malicious template containing the <code>_self.(&lt;string&gt;)</code> syntax, where <code>&lt;string&gt;</code> is a PHP code injection payload. For example, <code>_self.(&quot;system('whoami')&quot;)</code>.</li>
<li>The Twig engine parses the malicious template, and the <code>DotExpressionParser</code> handles the <code>_self.(&lt;string&gt;)</code> expression.</li>
<li>The <code>DotExpressionParser</code> incorrectly concatenates the attacker-controlled string into a <code>MacroReferenceExpression</code> name without identifier validation, creating a malicious macro reference.</li>
<li>The <code>MacroReferenceExpression::compile()</code> method then emits this raw, unvalidated name directly into the generated PHP source code.</li>
<li>The Twig engine loads and compiles the generated PHP source code, effectively executing the injected PHP code.</li>
<li>The injected PHP code executes system commands (e.g., <code>whoami</code>) or performs other malicious actions.</li>
<li>The attacker gains unauthorized access to the system or data, potentially leading to further compromise, such as data exfiltration or lateral movement.</li>
</ol>
<h2 id="impact">Impact</h2>
<p>Successful exploitation of this vulnerability allows an attacker to execute arbitrary PHP code on the server, leading to complete system compromise. This can result in data breaches, service disruption, and potential financial loss. Given the widespread use of Twig in PHP-based web applications, a significant number of systems are potentially vulnerable. The bypass of <code>SandboxExtension</code> makes this particularly dangerous, as it circumvents common security measures intended to restrict code execution.</p>
<h2 id="recommendation">Recommendation</h2>
<ul>
<li>Upgrade to Twig version 3.26.0 or later to patch CVE-2026-46640, as recommended in the GitHub advisory (<a href="https://github.com/advisories/GHSA-45vw-wh46-2vx8">https://github.com/advisories/GHSA-45vw-wh46-2vx8</a>).</li>
<li>Implement strict input validation and sanitization on any user-supplied data used in Twig templates to mitigate code injection risks.</li>
<li>Deploy the Sigma rule &ldquo;Detect Twig RCE via Macro Injection (CVE-2026-46640)&rdquo; to identify exploitation attempts in web server logs.</li>
</ul>
]]></content:encoded><category domain="severity">high</category><category domain="type">threat</category><category>rce</category><category>twig</category><category>php</category><category>code-injection</category></item></channel></rss>