Description
Twig is a template language for PHP. Prior to 3.27.0, ArrayExpression does not guard dynamic mapping keys that are coerced to strings, allowing PHP to invoke __toString() on a Stringable object used as a mapping key without calling SandboxExtension::ensureToStringAllowed(). This issue is fixed in version 3.27.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 PHP template language. The vulnerability is in ArrayExpression before version 3.27.0; dynamic mapping keys that are coerced to strings are not guarded. When a mapping key is a Stringable object, PHP calls its __toString() method without first invoking SandboxExtension::ensureToStringAllowed(), bypassing the sandbox's to-string restrictions. This failure to enforce a security policy (CWE-693) and improper handling of untrusted input during string coercion (CWE-863) can allow an attacker who can supply a template to trigger code execution or elevate privileges within the process.

Affected Systems

The affected product is the Twig template engine, version 3.x from twigphp:Twig. Any installation running a Twig version older than 3.27.0 is susceptible. The issue is fixed in Twig 3.27.0 and later, which guards dynamic mapping keys before invoking __toString().

Risk and Exploitability

The CVSS score of 7.1 indicates a high risk to confidentiality, integrity, and availability. With an EPSS of less than 1%, exploitation is currently considered unlikely. The vulnerability is not listed in the CISA KEV catalog. The likely attack vector involves an attacker-controllable template that supplies a Stringable object as a mapping key, which triggers __toString() without sandbox enforcement, leading to local privilege escalation or code execution on the host where Twig runs.

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

Remediation

No vendor fix or workaround currently provided.

OpenCVE Recommended Actions

  • Apply the official Twig 3.27.0 or newer patch that preserves sandbox enforcement for dynamic mapping keys.
  • If an upgrade cannot be performed immediately, ensure that template engines do not use Stringable objects as mapping keys, and validate any keys before processing to prevent unintended __toString() invocation.
  • Implement logging or monitoring for unexpected __toString() calls or template execution errors, which can serve as early indicators of an attempted bypass.

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

Tracking

Sign in to view the affected projects.

Advisories
Source ID Title
Github GHSA Github GHSA GHSA-5v5v-ww74-355v Twig: Sandbox `__toString()` policy bypass via dynamic mapping keys
History

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

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

Wed, 15 Jul 2026 13: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.27.0, ArrayExpression does not guard dynamic mapping keys that are coerced to strings, allowing PHP to invoke __toString() on a Stringable object used as a mapping key without calling SandboxExtension::ensureToStringAllowed(). This issue is fixed in version 3.27.0.
Title Twig: Sandbox `__toString()` policy bypass via dynamic mapping keys
Weaknesses CWE-693
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-15T12:47:14.623Z

Reserved: 2026-05-22T20:57:10.975Z

Link: CVE-2026-48806

cve-icon Vulnrichment

Updated: 2026-07-15T12:47:09.633Z

cve-icon NVD

No data.

cve-icon Redhat

No data.

cve-icon OpenCVE Enrichment

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

Weaknesses
  • CWE-693

    Protection Mechanism Failure

  • CWE-863

    Incorrect Authorization