Description
Twig is a template language for PHP. Prior to 3.26.0, several Twig language constructs trigger PHP string coercion on a Stringable operand without consulting SecurityPolicy::checkMethodAllowed(), allowing a sandboxed template author to invoke __toString() on objects reachable in the render context through conditional expressions, comparison operators, tests, template-loading tags, dynamic attribute names, spread arguments, the do tag, and the .. range operator. This issue is fixed in version 3.26.0.
Published: 2026-07-14
Score: 7.1 High
EPSS: < 1% Very Low
KEV: No
Impact: n/a
Action: n/a
AI Analysis

Impact

Twig is a template language for PHP. Before version 3.26.0, several language constructs in Twig trigger PHP string coercion on a Stringable operand without consulting SecurityPolicy::checkMethodAllowed(). This allows a sandboxed template author to invoke __toString() on objects reachable in the render context via conditional expressions, comparison operators, tests, template-loading tags, dynamic attribute names, spread arguments, the do tag, and the .. range operator. As a result, sandbox policy is bypassed, letting the attacker read or manipulate the underlying object data. The vulnerability is classified as CWE‑863.

Affected Systems

The vulnerability affects the Twig template engine for PHP (twigphp:Twig). All releases before 3.26.0 are susceptible, regardless of the specific minor or patch number. Individuals deploying older Twig versions in any environment that accepts user‑supplied templates must consider their risk. Updates are available from twigphp’s GitHub releases; version 3.26.0 and later contain the policy fix.

Risk and Exploitability

The CVSS base score is 7.1, indicating a moderate‑to‑high impact. The EPSS score is reported as < 1 %, suggesting that automated exploitation is currently unlikely, but the lack of KEV listing does not diminish the potential for targeted attacks. The likely attack vector is through the sandboxed template language itself: an attacker who can upload or influence templates can embed expressions that trigger string coercion, thereby invoking __toString() on a context object. Because the sandbox policy is bypassed, the attacker can read or manipulate object data. Given the moderate CVSS and low exploit probability, immediate remediation is advisable for any system that accepts templates from untrusted sources.

Generated by OpenCVE AI on July 31, 2026 at 04:41 UTC.

Remediation

No vendor fix or workaround currently provided.

OpenCVE Recommended Actions

  • Upgrade Twig to version 3.26.0 or later where the policy check has been added.
  • Ensure that only the patched release is present in the deployment environment and remove any older Twig packages.
  • If an upgrade is not immediately possible, employ a temporary restriction by limiting the objects available in the sandbox context to those with safe string representations or by removing the ability to perform string coercion within template expressions.

Generated by OpenCVE AI on July 31, 2026 at 04:41 UTC.

Tracking

Sign in to view the affected projects.

Advisories
Source ID Title
Debian DSA Debian DSA DSA-6311-1 php-twig security update
Github GHSA Github GHSA GHSA-pr2w-4gpj-cpq4 Twig: Sandbox: multiple `__toString()` policy bypasses via unguarded string coercion points
History

Wed, 15 Jul 2026 15:15:00 +0000

Type Values Removed Values Added
First Time appeared Twigphp
Twigphp twig
Vendors & Products Twigphp
Twigphp twig

Wed, 15 Jul 2026 14:30:00 +0000

Type Values Removed Values Added
Metrics ssvc

{'options': {'Automatable': 'no', 'Exploitation': 'none', 'Technical Impact': 'partial'}, 'version': '2.0.3'}


Tue, 14 Jul 2026 21:45:00 +0000

Type Values Removed Values Added
Description Twig is a template language for PHP. Prior to 3.26.0, several Twig language constructs trigger PHP string coercion on a Stringable operand without consulting SecurityPolicy::checkMethodAllowed(), allowing a sandboxed template author to invoke __toString() on objects reachable in the render context through conditional expressions, comparison operators, tests, template-loading tags, dynamic attribute names, spread arguments, the do tag, and the .. range operator. This issue is fixed in version 3.26.0.
Title Twig Sandbox: multiple `__toString()` policy bypasses via unguarded string coercion points
Weaknesses CWE-863
References
Metrics cvssV4_0

{'score': 7.1, 'vector': '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'}


cve-icon MITRE

Status: PUBLISHED

Assigner: GitHub_M

Published:

Updated: 2026-07-15T13:26:33.236Z

Reserved: 2026-05-19T22:16:39.503Z

Link: CVE-2026-47732

cve-icon Vulnrichment

Updated: 2026-07-15T13:20:13.684Z

cve-icon NVD

No data.

cve-icon Redhat

No data.

cve-icon OpenCVE Enrichment

Updated: 2026-07-31T04:45:17Z

Weaknesses