Track vulnerabilities like this one. Sign up free to get alerted when software you use is affected.
9.4

CVE-2026-46640: Twig templates may execute attacker‑controlled PHP code

CVE-2026-46640 · published 3 months ago
Summary

Versions 3.15.0 through 3.26.0 of the Twig template engine allow a specially crafted template to insert attacker‑controlled text that becomes raw PHP and runs when the template loads. This can let an attacker run any code on the server hosting the application. Update Twig to version 3.26.0 or later to stop the problem.

What to do
  • Update debian php-twig to version 3.27.0-0+deb13u1.
  • Update twig twig to version 3.26.0.
  • Update twig twig/twig to version 3.26.0.
  • Update debian php-twig to version 3.26.0-1.
  • Update symfony twig to version 3.26.0 or later.
Affected software
Ecosystem VendorProductAffected versions
Debian:13 debian php-twig < 3.27.0-0+deb13u1
Fix: upgrade to 3.27.0-0+deb13u1
composer twig twig >= 3.15.0, < 3.26.0
Fix: upgrade to 3.26.0
Packagist twig twig/twig >= 3.15.0, < 3.26.0
Fix: upgrade to 3.26.0
Ubuntu:Pro:20.04:LTS canonical php-twig All versions
Ubuntu:Pro:22.04:LTS canonical php-twig All versions
Ubuntu:Pro:24.04:LTS canonical php-twig All versions
Ubuntu:25.10 canonical php-twig All versions
Ubuntu:Pro:26.04:LTS canonical php-twig All versions
– twigphp twig >= 3.15.0, < 3.26.0
Debian:14 debian php-twig < 3.26.0-1
Fix: upgrade to 3.26.0-1
– symfony twig >= 3.15.0, < 3.26.0
cpe:2.3:a:symfony:twig:*:*:*:*:*:*:*:*
Original advisory text
Twig: Arbitrary PHP code execution via `_self.(<string>)` macro-reference compilation
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.
Fix within
Internet-facing 14 days
Internal At next upgrade
  • Not known to be exploited
  • Needs hands-on effort to exploit
  • Gives an attacker full control
Severity
9.4 Critical
Exploitation
<1% chance of attack within 30 days
Type
CWE-94Code Injection
Timeline
Published14 Jul 2026
Updated4 Nov 2026
First seen21 May 2026
Track software like this
Free during beta