Skip to main content

Twig CVE-2026-46639

HIGH
Protection Mechanism Failure (CWE-693)
2026-05-21 https://github.com/twigphp/Twig GHSA-mm6w-gr99-p3jj
7.1
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
    Obtain template-author privilege on sandboxed Twig app
  2. Delivery
    Craft template using object-destructuring with {% do %}
  3. Exploit
    Submit/save template to trigger compilation
  4. Execution
    Destructuring compiler emits getAttribute() with sandbox=false
  5. Persist
    Render bypasses SecurityPolicy allowlist
  6. Impact
    Exfiltrate restricted properties/getter return values via rendered output

Vulnerability Assessment

Weakness
CWE
OWASP Top 10:2025
A06:2025 - Insecure Design
ASVS 5.0
V15 - Secure Coding and Architecture Protection mechanism completeness
Exploitation Conditions

Requires (1) the target application to use Twig 3.24.0-3.25.x with SandboxExtension enabled, (2) an attacker able to write or submit Twig template source that will be rendered by the sandboxed environment (e.g., user-editable email templates, CMS theme overrides, multi-tenant template authoring), and (3) the {% do %} tag included in SandboxExtension's allowedTags, which the vendor describes as a common configuration. Limiting factors: installations that do not enable SandboxExtension are not exploitable via this bug (they have no sandbox to bypass in the first place); installations that exclude {% do %} from allowedTags are not exploitable; and the impact is bounded to public properties and public getters of objects already exposed to the template - private members and methods outside the template variable scope are not reachable.

Impact

No CVSS vector or EPSS score is provided, and the CVE is not on the CISA KEV list, so quantitative scoring is unavailable. Qualitatively, the vulnerability is meaningful but conditional: it requires an attacker to control a Twig template body inside a sandboxed environment AND for the {% do %} tag to be in allowedTags - a common but not universal configuration. Impact is confidentiality-oriented (read arbitrary public properties / invoke any public getter on exposed objects), not direct RCE, though leaked secrets, tokens, or internal state can be chained into broader compromise depending on what objects the host application passes to templates. Realistic priority is high for multi-tenant SaaS, CMS platforms, and any product letting end users author templates; low for installations that do not use SandboxExtension or do not expose template editing to untrusted users.

Exploit ScenarioDerived

A low-privileged tenant on a multi-tenant CMS that allows users to edit Twig email or page templates submits a template containing an object-destructuring assignment such as {% do { secret: app.user.apiToken } = somePassedObject %} (or a destructuring expression that reads a getter like getPassword()). Because the destructuring compiler emits getAttribute() with $sandboxed=false, SecurityPolicy's property/method allowlist is bypassed and the attacker exfiltrates session tokens, API keys, or internal user data through the rendered output. No public PoC has been published, but the advisory provides the exact compiler-level root cause, making PoC development straightforward.

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

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

Alert me

AnalysisAIv1 – May 21, 2026

Sandbox escape in Twig 3.24.0 through 3.25.x lets an attacker with write access to a sandboxed template read arbitrary public properties and invoke any public getter on objects exposed to the template, bypassing the SandboxExtension's SecurityPolicy allowlists. The flaw exists because the object-destructuring compiler hardcodes the $sandboxed flag to false when emitting CoreExtension::getAttribute() calls, so policy checks never run for destructuring expressions whenever the {% do %} tag is permitted. No public exploit identified at time of analysis, but the issue was responsibly disclosed with vendor-confirmed root cause and an upstream patch.

RemediationAI

Vendor-released patch: upgrade twig/twig to 3.26.0 or later via Composer (composer require twig/twig:^3.26 or composer update twig/twig), which forwards the active sandbox flag from the destructuring compiler to CoreExtension::getAttribute() so allowlists are enforced. Advisory details are at https://github.com/twigphp/Twig/security/advisories/GHSA-mm6w-gr99-p3jj and https://symfony.com/cve-2026-46639. If immediate upgrade is not possible, remove the {% do %} tag from SandboxExtension's allowedTags (this blocks the exploit path but breaks any legitimate templates relying on {% do %}), or disable user-submitted template authoring entirely until the package is updated; additionally, audit which objects are passed into sandboxed templates and remove any exposing sensitive properties or getters as a hardening step.

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 the PHP templating engine maintained by Symfony/SensioLabs and embedded in CMSes and frameworks (Drupal, Symfony, Craft CMS, eZ Platform, Shopware, Grav, etc.) where untrusted users can submit templates protected by SandboxExtension. The sandbox relies on SecurityPolicy allowlists enforced at runtime by CoreExtension::getAttribute(), which only checks allowlists when its $sandboxed argument is true. Twig 3.24.0 introduced object-destructuring assignment, whose compiler ObjectDestructuringSetBinary::compile() emits getAttribute() calls with $sandboxed hardcoded to false rather than the correct $env->hasExtension(SandboxExtension::class) check used by GetAttrExpression::compile(). The CWE-693 (Protection Mechanism Failure) classification captures the root cause: an existing security control silently does not run on a new code path.

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 7.1 HIGH
CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:L/VA:N/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
Low
Vulnerable system: Availability
None
Subsequent system: Confidentiality
None
Subsequent system: Integrity
None
Subsequent system: Availability
None

Lifecycle Timeline

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

DescriptionCVE.org

Description

The object-destructuring assignment syntax introduced in Twig 3.24.0 generates a call to CoreExtension::getAttribute() with the $sandboxed argument hardcoded to false, regardless of whether a SandboxExtension is active. This permanently disables the sandbox's property and method policy checks for every destructuring expression.

ObjectDestructuringSetBinary::compile() emits:

php
CoreExtension::getAttribute($this->env, $this->source, ..., \Twig\Template::ANY_CALL, false, false, false, ...);
//                                                                                ^^^^^
//                                                                       sandbox check never runs

Whereas GetAttrExpression::compile() correctly passes $env->hasExtension(SandboxExtension::class).

An attacker with write access to a sandboxed Twig template can read any public property or invoke any public getter on objects passed to the template engine, bypassing SecurityPolicy restrictions. The exploit requires only the {% do %} tag to be in allowedTags, which is a common configuration.

Resolution

The destructuring compiler now forwards the active sandbox flag to getAttribute() so property/method allowlists are enforced.

Credits

Twig would like to thank Anvil Secure in collaboration with Claude and Anthropic Research for reporting and fixing the issue.

Executive ViewAI

Why It Matters

Twig versions 3.24.0 through 3.25.x contain a sandbox escape vulnerability allowing template writers to access arbitrary object properties and methods; no public exploit identified at time of analysis. Organizations using Twig with user-supplied or untrusted template sources face risk of unauthorized data disclosure through compromised template authorship.

Business Impact: High
Compensating Controls

No vendor-released patch identified at time of analysis. Interim mitigations: (1) restrict template write access to verified internal personnel only, (2) limit objects exposed to sandboxed templates-expose only essential properties, (3) implement code review for template modifications, (4) evaluate alternative templating engines if user-supplied templates are non-critical to operations.

Threat Intelligence Overview

EPSS Score
0.1%
Top 76% exploitable
Threat Intel
1
1 source
Social Media
1
Sightings
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 No
EPSS 0.1%
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
None
System Exposure· derived
Open
Automatable· derived
No
Human Impact
High

Priority Score

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

Attack Technique

Authentication bypass attacks exploit flaws in the verification mechanisms that control access to systems and applications.

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