Skip to main content

Twig CVE-2026-46633

HIGH
Code Injection (CWE-94)
2026-05-21 https://github.com/twigphp/Twig GHSA-7p85-w9px-jpjp
8.7
CVSS 4.0 · Vendor: https://github.com/twigphp/Twig
View

Attack ChainAIDerived

Hypothetical attack flow derived from CVE metadata – not a confirmed exploit chain

  1. Access
    Identify Twig-based app accepting template input
  2. Delivery
    Submit template name containing single quote and PHP payload
  3. Exploit
    Trigger compilation of parent template with {% use %}
  4. Execution
    Malicious PHP written to compiled cache file
  5. Persist
    Cache file included by PHP process
  6. Impact
    Arbitrary 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 {% use %} tag and is then passed through Compiler::string() in ModuleNode::compileConstructor() - typically via user-supplied template paths, tenant-authored templates, theme/skin selection inputs, or any API parameter routed into the Twig loader. The single quote character must survive any application-level filtering. The vulnerability is reachable even from sandboxed templates because Twig's SecurityPolicy unconditionally permits {% use %} regardless of allowedTags configuration, so sandbox mode does not limit exploitation. Limiting factors: deployments that hardcode template names server-side and never expose them to user input are not exploitable, and the affected version range is strictly Twig before 3.26.0.

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 {% use %} - not arbitrary network input - so widespread untargeted scanning is unlikely. CISA KEV does not list this CVE and no public exploit identified at time of analysis, suggesting risk is currently potential rather than active. Note that the CWE is CWE-94 and the disclosure is detailed enough (including the exact compiler function and bypass primitive) that exploit development is straightforward for a competent attacker.

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 '.system($_GET[0]).'. When Twig compiles a parent template containing {% use 'attacker_name' %}, the compiled cache file contains executable attacker PHP; the next request that loads the cache executes it in the web server process, yielding RCE that bypasses the Twig sandbox entirely. No public exploit identified at time of analysis, but the advisory describes the primitive in enough detail that weaponization is straightforward.

This Week Schedule remediation this week. Why: HIGH severity (CVSS 7.0-8.9).
Patch available 0.4% exploitation probability (EPSS)

Get an e-mail when this CVE is exploited, patched or re-scored. Free account.

Alert me

AnalysisAIv1 – 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

composer twig/twig fix: 3.26.0

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

Vendor (https://github.com/twigphp/Twig) PRIMARY 8.7 HIGH
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

Attack Vector
Network
Attack Complexity
Low
Attack Requirements
None
Privileges Required
Low
User Interaction
None
Vulnerable system: Confidentiality
High
Vulnerable system: Integrity
High
Vulnerable system: Availability
High
Subsequent system: Confidentiality
None
Subsequent system: Integrity
None
Subsequent system: Availability
None

Lifecycle Timeline

1
CVSS changed
Jul 14, 2026 - 22:22 NVD
8.7 (HIGH)

DescriptionCVE.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

Why It Matters

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.

Business Impact: Severe
Compensating Controls

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

EPSS Score
0.4%
Top 42% exploitable
Threat Intel
1
1 source
Exploit
POC
Public exploit code exists
Data Quality
4 sources
Confidence: Medium

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.

SignalValue
Severity HIGH
CISA KEV No
Public POC Yes
EPSS 0.4%
Patch available Yes
Active threat No
Deciding rule
HIGH severity (CVSS 7.0-8.9)
What every action level means
Emergency Immediate action required. Criteria: CRITICAL + in CISA KEV (actively exploited) without patch, OR CRITICAL + EPSS > 30% without patch, OR CRITICAL + active threat signals without patch.
Act Now Prioritize within 24-48h. Criteria: in KEV with patch available, OR CRITICAL + public POC, OR HIGH + EPSS > 10%, OR CRITICAL + active threat, OR any CRITICAL severity.
This Week Schedule remediation this week. Criteria: HIGH severity (CVSS 7.0-8.9). Patch within normal change window.
This Month Plan within 30 days. Criteria: MEDIUM severity (CVSS 4.0-6.9), lower exploitation probability. Include in regular patch cycle.
Monitor Track and reassess. Criteria: LOW severity (CVSS 0.1-3.9), minimal exploitation risk. No immediate action needed.

SSVC AssessmentENISA

SSVC Decision· derived
Scheduled
Exploitation· derived
Poc
System Exposure· derived
Open
Automatable· derived
No
Human Impact
Very High

Priority Score

64
Low Medium High Critical
KEV: 0
EPSS: 0
CVSS: +44
PoC: +20
Weaponized: 0
Threat intel: 0
Gov advisory: 0

Attack Technique

Code Injection CRITICAL

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

pkg:composer/twig_twig

More in PHP

View all
CVE-2019-11043 CRITICAL POC
9.8 Oct 28

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

CVE-2012-1823 CRITICAL POC
9.8 May 11

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

CVE-2016-1555 CRITICAL POC
9.8 Apr 21

(1) boardData102.php, (2) boardData103.php, (3) boardDataJP.php, (4) boardDataNA.php, and (5) boardDataWW.php in Netgear

CVE-2018-11138 CRITICAL POC
9.8 May 31

The '/common/download_agent_installer.php' script in the Quest KACE System Management Appliance 8.0.318 is accessible by

CVE-2024-11680 CRITICAL POC
9.8 Nov 26

ProjectSend versions prior to r1720 are affected by an improper authentication vulnerability. Rated critical severity (C

CVE-2025-49113 CRITICAL POC
9.9 Jun 02

Roundcube Webmail contains a critical PHP object deserialization vulnerability (CVE-2025-49113, CVSS 9.9) that allows au

CVE-2017-9841 CRITICAL POC
9.8 Jun 27

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

CVE-2025-0108 HIGH POC
8.8 Feb 12

Palo Alto Networks PAN-OS management web interface contains an authentication bypass allowing unauthenticated attackers

CVE-2021-25298 HIGH POC
8.8 Feb 15

Nagios XI version xi-5.7.5 is affected by OS command injection. Rated high severity (CVSS 8.8), this vulnerability is re

CVE-2021-25296 HIGH POC
8.8 Feb 15

Nagios XI version xi-5.7.5 is affected by OS command injection. Rated high severity (CVSS 8.8), this vulnerability is re

CVE-2013-4983 CRITICAL POC
10.0 Sep 10

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

CVE-2023-6553 CRITICAL POC
9.8 Dec 15

The Backup Migration plugin for WordPress is vulnerable to Remote Code Execution in all versions up to, and including, 1

This site uses cookies essential for authentication and security. No tracking or analytics cookies are used. Privacy Policy