Skip to main content

Twig CVE-2026-47732

HIGH
Improper Input Validation (CWE-20)
2026-06-05 https://github.com/twigphp/Twig GHSA-pr2w-4gpj-cpq4
7.1
CVSS 4.0 · Vendor: https://github.com/twigphp/Twig
Share

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/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X

Primary rating from Vendor (https://github.com/twigphp/Twig) · only source for this CVE.

CVSS VectorVendor: https://github.com/twigphp/Twig

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/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X
Attack Vector
Network
Attack Complexity
Low
Privileges Required
Low
User Interaction
None
Scope
X

Lifecycle Timeline

4
Re-analysis Queued
Jul 14, 2026 - 22:22 vuln.today
cvss_changed
CVSS changed
Jul 14, 2026 - 22:22 NVD
7.1 (HIGH)
Source Code Evidence Fetched
Jun 05, 2026 - 22:15 vuln.today
Analysis Generated
Jun 05, 2026 - 22:15 vuln.today

DescriptionCVE.org

Description

SandboxNodeVisitor enforces SecurityPolicy::checkMethodAllowed() for implicit __toString() calls by wrapping selected AST nodes in CheckToStringNode. The set of wrapped nodes is incomplete, and several Twig language constructs still trigger PHP string coercion on a Stringable operand without first consulting the policy. A sandboxed template author can therefore invoke __toString() on any object reachable in the render context, even when __toString on its class is not allowlisted.

Confirmed bypass vectors:

  • Conditional expressions (a ? b : c, a ?: b, a ?? b) used as the input of a string-coercing filter or as a filter/function argument.
  • The matches operator and the loose comparison operators (==, !=, <, >, <=, >=, <=>), which coerce a Stringable operand to string and can be used as an oracle to recover the value byte by byte (no tag, filter or function needs to be allowlisted).
  • Twig tests in general (which were never policy-gated), in particular is empty which casts a Stringable value via (string) $value in CoreExtension::testEmpty().
  • Null-coalesce expressions nested in concatenation, and the direct output of allowed functions or filters that return a Stringable object.
  • Arguments passed to allowed object methods, template-name expressions of template-loading tags (include, extends, use, ...), dynamic attribute/property names, and spread arguments from Traversable objects.
  • The do tag and the .. range operator.

Resolution

The sandbox now wraps every child node that the parent will string-coerce at runtime, instead of relying on a hardcoded list of node types in SandboxNodeVisitor. A new Twig\Node\CoercesChildrenToStringInterface lets nodes declare which of their children must be guarded; core nodes (concatenation, comparison and range binaries, filter/function/test expressions, do, include, extends, use, ...) implement it. Spread arguments are materialised and policy-checked via the new SandboxExtension::ensureSpreadAllowed(), and dynamic attribute names are checked at runtime inside CoreExtension::getAttribute().

Credits

Twig would like to thank Anthropic Glasswing and El Kharoubi Iosif for reporting the issues, and Fabien Potencier for providing the fixes.

AnalysisAI

Sandbox policy bypass in Twig templating engine versions 3.25.0 and earlier allows sandboxed template authors to invoke arbitrary __toString() methods on any Stringable object reachable in the render context, even when those methods are not allowlisted by SecurityPolicy::checkMethodAllowed(). The flaw stems from SandboxNodeVisitor only wrapping a hardcoded subset of AST nodes in CheckToStringNode, leaving many string-coercion points (conditional expressions, comparison/matches operators, tests, ranges, includes, spread arguments) unguarded - and the comparison-operator vector enables byte-by-byte oracle recovery of sensitive object string forms. No public exploit identified at time of analysis; fix shipped in Twig 3.26.0 (also referenced by Symfony's advisory page).

Technical ContextAI

Twig is the widely deployed PHP templating engine maintained by the Symfony ecosystem (CPE pkg:composer/twig_twig). Its sandbox mode is intended for rendering untrusted template source by gating method calls - including implicit __toString() invocations on Stringable objects - through a SecurityPolicy. The root cause (CWE-20, Improper Input Validation) is that SandboxNodeVisitor enforced the policy only by recognizing a closed list of AST node types that obviously coerce to string (e.g., concatenation, print), missing many other constructs where PHP performs implicit string coercion: ternary/null-coalesce expressions feeding string-coercing operators, the matches regex operator, loose comparison operators (==, !=, <, >, <=, >=, <=>), the entire test category (notably is empty via CoreExtension::testEmpty()'s (string) $value cast), the do tag, the .. range operator, template-name expressions on include/extends/use, dynamic attribute/property names, and spread arguments unpacked from Traversable objects. The fix replaces the hardcoded list with a Twig\Node\CoercesChildrenToStringInterface so each node type declares which children must be guarded, and adds runtime checks for spread arguments (SandboxExtension::ensureSpreadAllowed()) and dynamic attribute names (CoreExtension::getAttribute()).

RemediationAI

Vendor-released patch: upgrade twig/twig to 3.26.0 or later via Composer (composer require twig/twig:^3.26.0), per the GHSA-pr2w-4gpj-cpq4 advisory and the v3.26.0 release notes which bundle this fix alongside several other sandbox CVEs (CVE-2026-46627 through CVE-2026-46640). If immediate upgrade is not possible, the most effective compensating control is to disable the Twig sandbox path for untrusted templates and instead render those templates in an isolated process or container with no access to sensitive objects in the render context - accepting the operational cost of process isolation. As a narrower mitigation, audit the render context passed into sandboxed templates and remove any Stringable objects whose string form is sensitive (credentials, session tokens, internal IDs), since the oracle vector requires a reachable Stringable to be useful; this is brittle because adding sensitive Stringable objects later re-introduces the risk. Generic SecurityPolicy tightening (shrinking allowed tags/filters/functions) does NOT block the comparison-operator oracle described in the advisory, so do not rely on it. Full advisory: https://github.com/twigphp/Twig/security/advisories/GHSA-pr2w-4gpj-cpq4.

More in PHP

View all
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-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

CVE-2024-46506 CRITICAL POC
10.0 May 13

NetAlertX (formerly PiAlert) versions 23.01.14 through 24.x before 24.10.12 allow unauthenticated command injection thro

CVE-2024-8353 CRITICAL POC
9.8 Sep 28

The GiveWP - Donation Plugin and Fundraising Platform plugin for WordPress is vulnerable to PHP Object Injection in all

Share

CVE-2026-47732 vulnerability details – vuln.today

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