Skip to main content

Twig CVE-2026-48806

HIGH
Protection Mechanism Failure (CWE-693)
2026-06-30 https://github.com/twigphp/Twig GHSA-5v5v-ww74-355v
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
    Gain template authoring access in sandbox-enabled app
  2. Delivery
    Craft template using Stringable context object as dynamic array mapping key
  3. Exploit
    Twig compiles ArrayExpression without CheckToStringNode wrapping
  4. Execution
    PHP invokes __toString() directly at runtime
  5. Persist
    Sandbox policy never consulted
  6. Impact
    Sensitive object data disclosed in rendered template 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

Exploitation requires the ability to author and execute sandboxed Twig templates - specifically, write access to template content that is rendered server-side using Twig's SandboxExtension. The vulnerable code path is triggered only when a Stringable object reachable in the render context is used as a dynamic mapping key in an array expression (e.g., {(obj): 'value'}). Direct output of the same object via {{ obj }} is correctly blocked by the existing sandbox policy, meaning this bypass is path-specific. Exploitation is limited to deployments where untrusted or semi-trusted users can submit Twig template content for server-side rendering - such as CMS platforms, multi-tenant SaaS, or low-code builders using Twig. Installations where template authorship is restricted to trusted developers are not at meaningful risk.

Impact

No CVSS vector or EPSS score is present in the provided data, so formal severity metrics cannot be cited as confirmed. Based on the vulnerability description, the attack surface is narrow: exploitation is gated on the ability to author and execute sandboxed Twig templates, which typically implies some level of privileged or trusted access to the application (e.g., a CMS where authenticated users can submit templates, or a multi-tenant SaaS platform). The POC is technically trivial - a single Twig expression - meaning anyone with template authoring access can exploit it with no advanced skill. The impact is limited to information disclosure via __toString() return values; there is no evidence from the description of code execution, integrity modification, or denial of service. No KEV listing means active exploitation is not confirmed by CISA. The combination of a narrow attack surface, low-complexity exploit, and limited-scope impact places this in a moderate real-world priority tier - critical only for deployments that expose Twig sandbox template authoring to untrusted or semi-trusted users.

Exploit ScenarioDerived

An authenticated user of a multi-tenant PHP application - where the application uses Twig sandbox mode to render user-submitted templates - crafts the expression {% set arr = {(sensitiveObj): 'value'} %} referencing a Stringable object from the render context. Because ArrayExpression does not trigger sandbox policy checks on mapping keys, PHP coerces the object to a string by calling __toString() directly, and the returned sensitive data (e.g., serialized credentials, internal state) appears in the rendered page output. A publicly available proof-of-concept is embedded in the GitHub security advisory GHSA-5v5v-ww74-355v.

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

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

Alert me

AnalysisAIv1 – Jun 30, 2026

Sandbox __toString() policy enforcement in Twig is bypassed via dynamic array mapping keys, allowing sandboxed template authors to invoke __toString() on arbitrary context objects without sandbox policy checks. This is a residual bypass of the previously patched CVE-2026-47732, rooted in ArrayExpression failing to declare dynamic mapping keys as string-coercion sites through CoercesChildrenToStringInterface. The reliable demonstrated impact is unauthorized disclosure of sensitive data returned by __toString() on objects that the sandbox was explicitly configured to protect - no public KEV listing exists, but a clear proof-of-concept is embedded in the advisory.

RemediationAI

Upgrade to Twig v3.27.0 or later, which resolves the bypass by having ArrayExpression implement CoercesChildrenToStringInterface, causing the sandbox visitor to wrap dynamic mapping keys with CheckToStringNode and consult the sandbox policy before PHP coerces the key to a string. The patched release is available at https://github.com/twigphp/Twig/releases/tag/v3.27.0 and documented in the Symfony advisory at https://symfony.com/blog/cve-2026-48806-sandbox-tostring-policy-bypass-via-dynamic-mapping-keys. If an immediate upgrade is not feasible, the most effective compensating control is to revoke or restrict template authoring access for untrusted users entirely, as the vulnerability exists specifically in the sandbox layer meant to safely execute untrusted templates - no per-feature toggle within the sandbox can close this gap on unpatched versions. Disabling dynamic mapping key support in user-supplied template review pipelines is operationally disruptive but eliminates the attack surface.

Affected Packages

composer twig/twig fix: 3.27.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 PHP templating engine (composer package twig/twig) widely used as the default renderer in Symfony and many other PHP frameworks. Its sandbox extension enforces a __toString() policy through SandboxExtension::ensureToStringAllowed(), which is invoked by CheckToStringNode wrappers the sandbox visitor injects at compile time. In 3.26.0, the visitor was extended to wrap string-coercion sites by checking whether the parent node implements CoercesChildrenToStringInterface. ArrayExpression - which compiles dynamic array mapping keys into PHP (string) casts or raw coercions - did not implement that interface, leaving those sites unguarded. CWE-693 (Protection Mechanism Failure) precisely describes the root cause: a protection mechanism exists and works for most code paths, but a specific compile path was excluded, creating a silent enforcement gap. The CPE pkg:composer/twig/twig scopes the affected surface to the Composer-distributed Twig library.

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
vuln.today AI 4.3 MEDIUM

PR:L reflects required template-authoring access; C:L scoped to __toString() disclosure only; no integrity or availability impact identified.

3.1 AV:N/AC:L/PR:L/UI:N/S:U/C:L/I:N/A:N
4.0 AV:N/AC:L/AT:N/PR:L/UI:N/VC:L/VI:N/VA:N/SC:N/SI:N/SA:N

Primary rating from Vendor (https://github.com/twigphp/Twig).

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

This is a residual bypass of CVE-2026-47732 / GHSA-pr2w-4gpj-cpq4 left after the initial fix for unguarded __toString() calls.

In 3.26.0 the sandbox visitor was extended to wrap every child node that its parent will string-coerce at runtime with CheckToStringNode, gated by the new CoercesChildrenToStringInterface. ArrayExpression did not implement the interface for its mapping keys: when a dynamic key expression resolves to a Stringable object, ArrayExpression::compile() emits a raw (string) cast (via StringCastUnary for ContextVariable keys, and no cast at all for richer key expressions). PHP then invokes __toString() directly, without ever calling SandboxExtension::ensureToStringAllowed().

A sandboxed template author can therefore trigger __toString() on any object reachable in the render context by using it as a dynamic mapping key, for example:

twig
{% set arr = {(obj): "value"} %}

Direct output of the same object is correctly blocked, which makes this a clear policy enforcement gap. The reliable demonstrated impact is unauthorised disclosure of data returned by __toString().

Resolution

ArrayExpression now declares its dynamic mapping keys as string-coercion sites through CoercesChildrenToStringInterface, so the sandbox visitor wraps them with CheckToStringNode and the policy is consulted before PHP coerces the key to a string. The compiler also keeps an explicit (string) cast around the wrapped expression so PHP type errors on non-string keys are preserved.

As a side effect, any expression is now accepted as a dynamic mapping key (not only context variables); this is documented as a new feature on the 3.x branch.

Credits

Twig would like to thank El Kharoubi Iosif for reporting the issue and Fabien Potencier for providing the fix.

Threat Intelligence Overview

EPSS Score
0.2%
Top 85% exploitable
Prevalence
Medium
default templating engine for Symfony PHP framework
Threat Intel
1
1 source
Social Media
1
Sightings
Data Quality
5 sources
Confidence: Medium
NVD CVE.org EPSS Vulnrichment GHSA CIRCL GitHub

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.2%
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
None
System Exposure· derived
Open
Automatable
No
Human Impact· derived
Medium
Technical Impact
Partial

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