Skip to main content

Twig CVE-2026-48807

HIGH
Protection Mechanism Failure (CWE-693)
2026-06-30 https://github.com/twigphp/Twig GHSA-8x9c-rmqh-456c
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 sandboxed template authoring access
  2. Delivery
    Identify Stringable object in render context with sensitive data
  3. Exploit
    Craft template using `in` operator with character-by-character probes
  4. Execution
    PHP spaceship operator coerces object via __toString() undetected
  5. Persist
    Observe output differences per probe
  6. Impact
    Reconstruct sensitive string via equality oracle

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

The attacker must hold the role of sandboxed template author - a user or role explicitly permitted to submit Twig templates rendered under sandbox mode. Sandbox mode must be active on the affected Twig instance (either global sandbox or per-source via SourcePolicyInterface); deployments that never enable sandbox mode are not affected. For the join/replace filter vector, the targeted objects must be inside a Traversable container (not a plain PHP array, which was already protected by the CVE-2026-47732 patch) that is accessible from the template render context. For the in/not in oracle vector, any Stringable object reachable in the template context is sufficient, whether in an array or Traversable haystack, or on either operand side. Exploitation is not possible when: template authoring access is restricted to trusted parties; no Stringable objects with sensitive string representations are present in the render context; or Twig sandbox mode is not used in the deployment.

Impact

No CVSS score or vector was supplied in the input data; all severity signals are independently assessed. The exploitation prerequisite - sandboxed template authoring access - is a meaningful privilege boundary: only deployments that expose Twig sandbox rendering to untrusted parties (multi-tenant SaaS platforms, user-customisable CMS themes, hosted page builders) are materially at risk. For such deployments the risk is HIGH because the oracle attack path requires no special object structure beyond an accessible Stringable, and the technique is fully described in the public advisory text. For deployments where template authors are trusted internal parties the practical risk is LOW despite the policy bypass. No EPSS score is available, and the vulnerability is not listed in CISA KEV, so exploitation probability at population scale is unconfirmed. The information-disclosure oracle is the most impactful finding: it allows data exfiltration from the render context without triggering method-allowlist enforcement, meaning existing monitoring that watches for disallowed method calls would not fire. There is no CVSS vector to cross-check against the description, so the attack-vector classification (network) is inferred from Twig's typical deployment model and independently assessed below.

Exploit ScenarioDerived

An untrusted customer of a SaaS platform that allows custom Twig templates crafts a template containing a loop of in operator probes - for example {% if chr(65) in someObject %} - where someObject is a Stringable context variable holding a sensitive value such as an API key. PHP's spaceship operator inside inFilter() coerces the object to a string without consulting the sandbox policy; by iterating candidate characters and observing rendered output differences, the attacker reconstructs the full string character by character. No public exploit code has been identified at time of analysis, but the technique is described in sufficient detail in the advisory that construction requires minimal reverse-engineering effort.

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 policy bypass in Twig PHP template engine allows sandboxed template authors to trigger __toString() calls on objects explicitly blocked by SecurityPolicy::$allowedMethods, through two distinct coercion paths: Traversable inputs to the join and replace filters, and PHP's implicit spaceship-operator coercion inside the in/not in operator implementation. Beyond unauthorized method invocation, the in operator can be chained into a character-by-character equality oracle, enabling reconstruction of the full string value of sensitive objects - such as tokens or credentials passed into the render context - without any direct method invocation being permitted. This is a residual bypass of CVE-2026-47732; no public exploit code has been identified at time of analysis, and the issue is patched in Twig v3.27.0.

RemediationAI

Upgrade Twig to version 3.27.0 or later via Composer (composer update twig/twig); this is the only confirmed fix and closes both coercion bypass paths at the engine level. The release is available at https://github.com/twigphp/Twig/releases/tag/v3.27.0. If an immediate upgrade is not feasible, the most effective compensating control is to audit the template render context and remove or replace all Stringable-implementing objects that carry sensitive data - eliminating the valuable targets rather than the bypass path itself; the trade-off is that this is difficult to guarantee exhaustively as the object graph grows. A second compensating control is to restrict sandboxed template authoring access to trusted internal parties, which eliminates the attacker role entirely but may not be operationally viable in multi-tenant deployments. Generic sandbox-hardening measures such as restricting allowed filters/functions do not close this bypass because the affected code paths (join, replace, in, not in) are standard Twig operators, not exotic extensions. No patch-free workaround at the Twig engine level has been identified.

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 (pkg:composer/twig/twig) is a PHP template engine widely used in Symfony-based applications that provides a sandbox extension (SandboxExtension) enforcing a SecurityPolicy over permitted methods, properties, and type coercions. The root cause is CWE-693 (Protection Mechanism Failure): SandboxExtension::ensureToStringAllowed() recursively inspects PHP arrays for Stringable objects before allowing string coercion, but the recursion stops at the PHP array type boundary - a Traversable value at the same position is passed through without materialising its elements. CoreExtension::join() and CoreExtension::replace() subsequently materialise those Traversable inputs via self::toArray() and feed them to implode()/strtr(), both of which implicitly invoke __toString() on any Stringable elements without the sandbox policy being consulted. A dual-interface object implementing both Stringable and Traversable also exposes a second gap: the container's own __toString() is checked, but elements yielded by getIterator() are not. Separately, InBinary and NotInBinary AST nodes compile to CoreExtension::inFilter(), which falls through to PHP's <=> (spaceship) operator; PHP's implicit string coercion during comparison entirely bypasses SandboxNodeVisitor. The fix in v3.27.0 addresses both paths: ensureToStringAllowed() now materialises Traversable operands under isSandboxed($source), and the In/NotIn binary nodes now implement CoercesChildrenToStringInterface so SandboxNodeVisitor wraps both operands in CheckToStringNode before inFilter() is reached.

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 8.5 HIGH

Network vector (templates submitted remotely); low privilege (sandboxed author role required); scope change as sandbox policy is bypassed; high confidentiality via oracle exfiltration, low integrity from unauthorized coercions.

3.1 AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:L/A:N
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).

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. It covers two related coercion points that were not caught by the original patch.

Traversable in join and replace filters. SandboxExtension::ensureToStringAllowed() recurses into PHP arrays so that a Stringable object hidden inside an array argument cannot be string-coerced without consulting the security policy. The recursion stops at PHP arrays: a Traversable value passed at the same position is not materialised, so its contents are not policy-checked. CoreExtension::join() and CoreExtension::replace() later materialise such Traversable inputs through self::toArray() and feed them to implode() / strtr(), both of which implicitly call __toString() on contained Stringable objects. The bypass also reproduces when the container implements both Stringable and Traversable: the container's own __toString() is policy-checked, but the elements yielded by getIterator() are not, and the consuming filters still coerce them to string.

in and not in operators. InBinary and NotInBinary compile to CoreExtension::inFilter(), which falls through to PHP's <=> operator when comparing a string with a Stringable object. PHP coerces the object to string via __toString() without the sandbox policy being consulted. Beyond the direct side effect, in can also be used as a content-leak oracle: each probe against an attacker-chosen needle leaks one bit of equality, and chained probes can reconstruct the string returned by __toString() even when every method is denied. The bypass reproduces with both array and Traversable haystacks, and on both operand sides.

A sandboxed template author who is allowed to call join / replace, or to use the in / not in operators, can therefore trigger a disallowed __toString() method on objects reachable from the render context, even when that method is not on SecurityPolicy::$allowedMethods. The bypass reproduces both under global sandbox mode and when sandboxing is enabled through SourcePolicyInterface.

Resolution

SandboxExtension::ensureToStringAllowed() now also recurses into Traversable operands when sandboxing is active for the current source: each value is materialised once and run through the same array-recursion path, so the policy is consulted before the filter implementation can coerce contained objects to strings. This applies to plain Traversable operands as well as to containers that implement both Stringable and Traversable: the container's own __toString() is still policy-checked, and the yielded elements are additionally checked. The materialisation is guarded by isSandboxed($source) so that non-sandboxed code paths do not pay the cost or change generator-exhaustion semantics.

InBinary and NotInBinary now implement Twig\Node\CoercesChildrenToStringInterface and declare both operands as string-coerced, so SandboxNodeVisitor wraps each operand in CheckToStringNode. The policy is consulted before CoreExtension::inFilter() reaches PHP's <=> operator, matching the existing protection on the other comparison binaries (Equal, Less, Greater, Spaceship, ...).

Credits

Twig would like to thank Vincent55 Yang and Fabien Potencier for reporting the issues and Fabien Potencier for providing the fix.

Threat Intelligence Overview

EPSS Score
0.2%
Top 86% exploitable
Prevalence
Medium
widely used in Symfony and PHP CMS ecosystems
Threat Intel
1
1 source
Social Media
1
Sightings
Data Quality
6 sources
Confidence: High
NVD CVE.org EPSS Vulnrichment GHSA CIRCL GitHub VulDB

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

Information disclosure occurs when an application unintentionally exposes sensitive data that aids attackers in reconnaissance or directly compromises security.

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