CVE-2026-46640·PHP vulnerability
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.
- Severity
- high
- Software
- PHP
- Fixed in
- 3.26.0
- Published
- 2026-07-14
Affected versions
From: 3.15.0
Until: 3.26.0
Fixed in: 3.26.0
How to fix this CVE
Update PHP and the Twig template engine to version 3.26.0 or later to remediate this critical template injection vulnerability. The vulnerability allows authenticated attackers to inject arbitrary PHP code through dynamic attribute syntax in Twig macros, which executes during template compilation rather than runtime. Immediately patch all affected systems and review template files for suspicious macro references or import aliases.
sudo dnf update php php-twigDefensia detects this vulnerability
How to check if you are affected
- Step 1: Check installed Twig version: php -r "echo Twig\\Environment::VERSION;" or composer show symfony/twig-bundle | grep Version
- Step 2: Verify if Twig is actively used in your PHP application by searching for .twig template files: find /var/www -name '*.twig' -type f | head -20
- Step 3: Search application logs and PHP error logs for compilation errors or warnings related to macro expressions: grep -i 'macro\|_self\.' /var/log/php-fpm/error.log | grep -v 'DEBUG'
- Step 4: Confirm the patch by running php -r "echo Twig\\Environment::VERSION;" and verify the version is 3.26.0 or higher
FAQ
What is CVE-2026-46640?
CVE-2026-46640 is a code injection vulnerability in Twig's template engine affecting versions 3.15.0 through 3.25.x. Attackers with authentication credentials can exploit dynamic attribute syntax in macros to inject raw PHP code that executes at template compilation time, leading to remote code execution.
Is CVE-2026-46640 being actively exploited?
No, this vulnerability is not currently listed on the CISA Known Exploited Vulnerabilities catalog, and no public exploits are available. However, the high CVSS score of 8.8 and the nature of the vulnerability warrant immediate patching.
What versions of PHP are affected by CVE-2026-46640?
This CVE affects Twig template engine versions 3.15.0 through 3.25.x when used with PHP. Any PHP installation using an affected Twig version is vulnerable, regardless of the PHP version itself.
How do I check if my server is vulnerable to CVE-2026-46640?
Run `php -r "echo Twig\\Environment::VERSION;"` to check your installed Twig version. If the version is between 3.15.0 and 3.25.x inclusive, your system is vulnerable and requires immediate patching to 3.26.0 or later.
Does Defensia detect CVE-2026-46640?
Yes — Defensia's CVE advisory scanner compares installed package versions against the NVD database. If PHP and Twig are installed on a monitored server, CVE-2026-46640 will appear in your dashboard with remediation steps.
Related PHP CVEs
References
Track CVEs across your fleet automatically
Defensia scans your Linux servers and tells you exactly which ones are running vulnerable versions — including CVE-2026-46640. Free for 1 server.
Get started free