Twig CVE-2026-46633
HIGHAttack ChainAIDerived
Hypothetical attack flow derived from CVE metadata – not a confirmed exploit chain
-
AccessIdentify Twig-based app accepting template input
-
DeliverySubmit template name containing single quote and PHP payload
-
ExploitTrigger compilation of parent template with {% use %}
-
ExecutionMalicious PHP written to compiled cache file
-
PersistCache file included by PHP process
-
ImpactArbitrary code execution as web user
Vulnerability Assessment
| Weakness |
CWE
OWASP Top 10:2025
A05:2025 - Injection
ASVS 5.0
V1 - Encoding and Sanitization Code injection prevention, sandbox exec
MITRE ATT&CK
2 techniques across 2 tactics: Execution, Initial Access The technique list with ATT&CK links and the kill-chain view is part of the Basic plan and up. |
| Exploitation Conditions | Attacker must be able to influence a template name that reaches a |
| Impact | No CVSS vector or EPSS score is available in the source data, so quantitative scoring cannot be cited. Qualitatively the impact is severe: full sandbox escape and remote code execution in the PHP worker process, which is precisely the threat model Twig sandboxing is supposed to prevent. The attack is automatable wherever user-supplied template names reach the renderer (multi-tenant SaaS, CMS extensions, template editors, themes), but it requires the attacker to control a template name passed to |
| Exploit ScenarioDerived | An attacker on a multi-tenant CMS or SaaS that lets tenants author Twig templates (or supply template names through a theme/extension upload, a profile field, or an API parameter) crafts a template whose name contains a single quote followed by PHP code such as |
Get an e-mail when this CVE is exploited, patched or re-scored. Free account.
Alert meAnalysisAIv1 – May 21, 2026
PHP code injection in Twig template engine versions before 3.26.0 allows attackers controlling template names in {% use %} tags to break out of compiled cache file string literals and execute arbitrary PHP code. The flaw bypasses the Twig sandbox entirely because SecurityPolicy unconditionally permits {% use %} regardless of allowedTags configuration. No public exploit identified at time of analysis, but the GitHub Security Advisory (GHSA-7p85-w9px-jpjp) discloses the full exploitation primitive.
RemediationAI
Vendor-released patch: 3.26.0 - upgrade composer dependency twig/twig to 3.26.0 or later (composer require twig/twig:^3.26.0) as the primary fix, per the GHSA-7p85-w9px-jpjp advisory. After upgrading, purge the existing Twig compiled cache directory so that any previously cached files generated from attacker-influenced template names are regenerated under the fixed compiler. If immediate patching is not possible, the practical compensating control is to ensure template names passed to the loader and to {% use %} are never derived from user input - restrict template selection to a server-controlled allowlist and reject any name containing a single quote; this is more reliable than relying on SecurityPolicy because {% use %} is unconditionally permitted regardless of allowedTags. Disabling the on-disk cache (cache => false on the Environment) does not eliminate execution risk because the injected PHP still runs the first time the template is compiled and loaded, so the upgrade or input-sanitization control should be applied even when caching is off.
Affected Packages
Source: OSV (Open Source Vulnerabilities)
Affects your stack
Affects 1 package in composer
Checking this CVE against your own stacks and servers is part of the Basic plan and up.
Technical ContextAI · show details
Twig is a widely deployed PHP templating engine (distributed as composer package twig/twig) used by Symfony, Drupal, and many other PHP frameworks. The root cause is a CWE-94 (Improper Control of Generation of Code) defect in Compiler::string(), which escapes double quotes, dollar signs, backslashes, NUL, and TAB characters when generating PHP string literals - but neglects single quotes. In ModuleNode::compileConstructor(), the template name from {% use %} flows through subcompile() to string() and is emitted inside a single-quoted PHP literal in the compiled cache file. A single quote in the template name closes the literal early, letting attacker-controlled content become executable PHP that runs when the cache file is included. Because compiled caches are loaded on subsequent requests, exploitation persists across process boundaries until the cache is purged.
Know when PHP gets its next vulnerability
- Watch products and get an email when something new is published
- Check this CVE against your own stack and servers
- Exploit and PoC references, threat intelligence from 22 sources
No credit card · 7-day full trial
Severity 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
Primary rating from Vendor (https://github.com/twigphp/Twig) · only source for this CVE.
CVSS VectorVendor: https://github.com/twigphp/Twig
Lifecycle Timeline
1DescriptionCVE.org
Description
Compiler::string() escapes ", $, \, NUL and TAB when generating PHP double-quoted string literals, but does not escape single quotes. In ModuleNode::compileConstructor(), the template name from a {% use %} tag is compiled via subcompile() -> string() and placed inside a surrounding PHP single-quoted string literal. A template name containing a single quote terminates that surrounding string early, allowing arbitrary PHP expressions to be injected into the compiled cache file.
The injected code executes within the PHP process when the cache file is first loaded, bypassing the Twig sandbox entirely and achieving remote code execution. SecurityPolicy unconditionally allows {% use %} regardless of the configured allowedTags, so this primitive is reachable from sandboxed templates as well.
Resolution
Compiler::string() now also escapes single quotes so that template names placed inside single-quoted PHP literals can no longer break out of the surrounding context.
Credits
Twig would like to thank Anvil Secure in collaboration with Claude and Anthropic Research for reporting the issue and providing the fix.
Executive ViewAI
The Twig template engine (all versions before 3.26.0) contains a critical PHP code injection vulnerability that allows attackers to execute arbitrary code by circumventing sandbox security protections entirely. Organizations using affected Twig versions face immediate risk of complete application and infrastructure compromise through template injection attacks.
No vendor-released patch identified at time of analysis. Interim mitigations: (1) Enforce strict allowlist validation on all template name inputs; (2) Disable or restrict {% use %} tag functionality in SecurityPolicy where feasible; (3) Deploy Web Application Firewall with template syntax injection detection rules; (4) Restrict filesystem permissions on template cache and source directories; (5) Enable detailed logging and real-time alerting on template engine activity; (6) Apply network segmentation to limit blast radius of compromised application instances.
Threat Intelligence Overview
How this decision was reached
The engine reads each signal below and applies a fixed list of rules from top to bottom. The first rule that matches sets the recommended action – like a statement, every line is shown.
What every action level means
SSVC AssessmentENISA
Priority Score
Attack Technique
Code injection occurs when an application accepts user input and passes it directly into a language interpreter or evaluator without proper sanitization.
Remote Code Execution represents the critical moment when an attacker successfully runs arbitrary code on a target system without physical access.
Affected Products (CPE)CVE.org
In PHP versions 7.1.x below 7.1.33, 7.2.x below 7.2.24 and 7.3.x below 7.3.11 in certain configurations of FPM setup it
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
The '/common/download_agent_installer.php' script in the Quest KACE System Management Appliance 8.0.318 is accessible by
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
GHSA-7p85-w9px-jpjp
NVD
CVE.org
EPSS
Exploit-DB